Re: Assigning regexpression to a variable

From: John W. Krahn (krahnj_at_telus.net)
Date: 10/29/04


Date: Fri, 29 Oct 2004 05:42:48 -0700
To: Perl Beginners <beginners@perl.org>

Prabahar Mosas wrote:
>
> On Fri, 29 Oct 2004 John W.Krahn wrote :
>
>>Prabahar Mosas wrote:
>>>
>>>specimen coding
>>>**************
>>>$value = 2422; $reg = '/\d/';
>>
>>The slashes (/) are the delimiters for the match operator, they
> are not a part of the regular expression, just like the quotes
> (') delimit the string but are not a part of it. Your "regular
> expression" says match a '/' character followed by a '\d' character
> followed by a '/' character.
>
> I agree your point. But that is simple regular expression.
> When I assign complex regular expressions into a variable it won't
> assign.
>
> eg $regex = 's/[A-Z]/[a-z]/g';

That is matching every *single* character in the range A-Z and replacing
*each* *character* with the *string* '[a-z]'.

> $regex = 's/\r//g';
> $regex = '/(^[^a-z])|/|(\.\.)/i'
> For this case What I need to do for that Mail me. Because this Problem is
> one of the barrier in my project.

It looks like you may be confused between a regular expression, which is
similar to a string, and the match, substitution and transliteration
operators, two of which use regular expressions. Have you read some of the
documentation on regular expressions and strings?

perldoc perlrequick
perldoc perlretut
perldoc perlre
perldoc perlop
perldoc perlreref

If you still think you need to do the above then:

perldoc -q "How do I match a pattern that is supplied by the user"
perldoc -f eval

John

-- 
use Perl;
program
fulfillment


Relevant Pages

  • Small regular expression parser
    ... the goal was to develop a very simple regular expression parser. ... sets are selected using the % character instead of \. ... into the string of the start of the match and the length of the match. ... Last there are a couple macros to help with captures. ...
    (comp.lang.lisp)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... abandoned it because I don't think Beautiful Code can be written in C: ... Pike's code doesn't implement a regular expression interpreter ... it makes no provision for a character which must occur at ... changeable index into the string it points-at and it expects the user ...
    (comp.programming)
  • Re: Checking last character of string for punctuation
    ... I'm a newbie with a newbie question. ... the string should be kept as is. ... This matches your string against the regular expression that you need to put ... Given the description of your problem, you might be interested in character ...
    (perl.beginners)
  • Re: RegularExpressions
    ... Start at the beginning of the string, or at the first line break character ... Basically, that is what a regular expression does, but in a more roundabout ... Notice that before the word BRE there are some other info that I dont ...
    (microsoft.public.dotnet.framework)
  • Re: How to Parse a string with Embedded Double Quotes
    ... I am not sure that I understand the regular expression ... So I tried escaping the double quotes, ... but this cleared my string out to a couple of spaces when I did a replace. ... >> to processing each part of the string character by character so that I ...
    (microsoft.public.dotnet.languages.vb)