Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > problems with regex matching - invalid ranges, quantifier follows nothing, etc.

Reply
Thread Tools

problems with regex matching - invalid ranges, quantifier follows nothing, etc.

 
 
Jack
Guest
Posts: n/a
 
      10-03-2006
Hi folks,

I want to be able to test any string (yes any string with any
combination of -, 0-9, +, -, [, and other non alphanumeric characters)
against a set of target strings (and with these also, anything goes in
these strings as well)..Here is an example of the code which as you can
see pattern matches:
while (<SOURCE2>) {
@temparray2 = split(/$delimiter/, $_);
for ($i=0;$i<=$#target;$i++)
{
if ($target[$i] =~ m/$temparray2[0]/i) { print " match "; }
}
} #end while

This works great and runs through the file matching each $temparray2[0]
element against a target set of elements in an array, until I run into
some character that Regex complains about. What do I need to do with
my code to allow the flexibility I am looking for, the ability to case
insensitively match many, many patterns I have against other complex
strings without the complaints ; do I need to preprocess $temparray2[0]
to remove non alphanumeric characters and if so, whats is the code to
strip these out - here is a example data where regex complains about
$temparray2[0]:
METHYLENETETRAHYDROFOLATE DEHYDROGENASE/METHENYLTETRAHYDROFOLATE
CYCLOHYDROLASE/FORMYLTETRAHYDROFOLATESYNTHETASE,
NADP(+)-DEPENDENTMETHYLTETRAHYDROFOLATE CYCLOHYDROLASE DEFICIENCY,
INCLUDED

Here are some example errors:

Invalid [] range "y-4" in regex; marked by <-- HERE in
m/1-naphthacenecarboxylic
acid, 2-ethyl-1,2,3,4,6,11-hexahydro-2,5,
7-trihydroxy-6,11-dioxo-4-[[2,3,6-tri
deoxy-4 <-- HERE
-O-[2,6-dideoxy-4-O-((2R-trans)-tetrahydro-6-methyl-5-oxo-2H-py
ran-2-yl)
-.alpha.-L-lyxo-hexopyranosyl]-3-(dimethylamino)-.alpha.-L-lyxo-hexopy
ranosyl]oxy]-, methyl ester,(1R-(1.alpha.,2.beta.,4.beta.))-(9CI)/ at
....

Quantifier follows nothing in regex; marked by <-- HERE in
m/METHYLENETETRAHYDRO
FOLATE DEHYDROGENASE/METHENYLTETRAHYDROFOLATE
CYCLOHYDROLASE/FORMYLTETRAHYDROFOL
ATESYNTHETASE, NADP(+ <-- HERE )-DEPENDENTMETHYLTETRAHYDROFOLATE
CYCLOHYDROLASE
DEFICIENCY, INCLUDED/ at ...

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      10-03-2006
Jack wrote:
> I want to be able to test any string (yes any string with any
> combination of -, 0-9, +, -, [, and other non alphanumeric characters)
> against a set of target strings (and with these also, anything goes in
> these strings as well).


perldoc -f quotemeta
perldoc perlreref (search for \Q and \E)

$pattern = "+ foo [0-a]";
if ($string =~ /\Q$pattern\E/) {
print "$string contained $pattern\n";
}

Paul Lalli

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      10-04-2006
Mumia W. (reading news) <(E-Mail Removed)> wrote:
> On 10/03/2006 09:33 AM, Jack wrote:


>> if ($target[$i] =~ m/$temparray2[0]/i) { print " match "; }

^
^

> if (index($target[$i],$temparray2[0]) >= 0) { print " match "; }



if (index(lc $target[$i], lc $temparray2[0]) >= 0) { print " match "; }


(which could become painful in a big loop...)


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regexp : invalid quantifier + Une Bévue Javascript 6 06-04-2008 06:57 PM
nested quantifier or unrecognized escape error Francois Massion Perl Misc 6 06-02-2006 10:38 AM
Quantifier...bigger than 32766...in regex leegee@gmail.com Perl Misc 19 05-07-2006 12:25 PM
Greedy quantifier - Java 0 07-11-2005 01:34 AM
Using a variable size with the repetition quantifier Philippe Aymer Perl Misc 12 10-14-2004 05:59 PM



Advertisments