Andrej Kastrin am Mittwoch, 14. Dezember 2005 08.54:
> Hi all
>
> I have a list of terms and I have to find out, if any one of them occur
> in my text. Example:
>
> term is e.g. ABCB1 wich is store in variable $w and my regular
> expression is  "...if /^TI.*?\s$w\s/m..." .That way I successfully found
> ABCB1, but if the therm is parenthesize (e.g. (ABCB1)) then I can't find
> nothing.
>
> I modify above expression with "...if /^TI.*?.$w./m...", to match any
> character before and behind $w, but problem still persist.
>
> Any suggestion; thanks in advance.

The problem here is that '(' and ')' in regexes have special meaning and must 
be "escaped".

The direct way:

my $w='\(ABCB1\)'; # done in $w itself

The generic way:

my $w='(ABCB1)';
/^TI.*?\s\Q$w\E\s/m; # done in the regex

For \Q and \E and all the chars with special meaning, see perldoc for:
perlre
perlretut
perlrequick

hth joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to