Re: regex problem unresolved



Ela <ela@xxxxxxxxxx> wrote:
I was suggested by experts to post runnable codes to seek advice.
Unfortunately, after 4-day trial, I'm unable to break down the large codes
written by others to a smaller one. And as what xhoster inferred exactly,
the matching string comes from a data file and therefore cannot be known in
advance.

It is a cyclic problem that if I had known which line of the perl codes that
makes regex fail, I might have already solved half of the problem. But I'm
really saying the truth that no line number printed. And there's a single
line of error saying "Invalid [] range "l-c" in regex; marked by <-- HERE in
m/^3-oxoacyl-[acyl-c
<-- HERE arrier protein] reductase fabg1$/"

Xho suggested 2 solutions. One is index instead of regex that I still don't
know what it means. Another one is to upgrade perl, which is impossible.

In fact, since input data file is needed and "oxoacyl" does exist in that
data file confirmed by search, I believe the fetch program first grabs all
the keywords and later uses the variable one by one to match.

Unfortunately, your problem descripton is still rather vague
which makes it difficult to come up with an answer. So let
me start with a summary of what I think I understood you're
trying to do:

You have a file 1 from which you read a string, lets call it
$to_match. That string you somehow have to use to find another
string within a file 2, lets call it $string_to_test.

Something from what you write above makes it look as if you
are only interested in exact matches, i.e. when $match_string
is identical to $string_to_test (the use of '^' and '$' in
the regular expression make it look a bit like that). In that
case the simplest comparison would be a plain

if ( $match_string eq $string_to_test ) ...

If, on the other hand you want to find $match_string anywhere
within $string_to_test then, as Xho pointed out, the index()
function probably is the best choice, see

perldoc -f index

since that will get rid of all the problems involved with
using a regex.

If you insist on using a regex then you will have to escape
all characters in $match_string that would be interpreted
by the regular expression matching system like e.g. the '-',
'[', ']' etc. before you use it in the regex.

But if, finally, the file 1 already contains strings meant to
be regular expressions than it looks as i this file simply
contains flawed regex strings and there's hardly anything
you can do to solve the problem (unless you know exactly
which flaws are to be expected and can correct them before
you use $match_string in a regular expression).

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: Which RegEx Testing Tool Do You Prefer?
    ... public static string ReplaceAmpersand ... I used both Expresso and Regex Buddy to come up with this. ... > have to force the 2.0 Regular Expression Validator to fail when the & is ... >> create patterns of a large variety of types. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: RegExp to capture IMAGE SRC only.
    ... OBJECT's SRC. ... You will have to define the expected string clearly. ... So you will have to fine tune your regex again and again, ... I put your regular expression in both The Regex Coach, ...
    (comp.lang.javascript)
  • Re: Regular expression question
    ... Your regular expression isn't matching the object string. ... use warnings; ... Changing the regex to this ...
    (perl.beginners)
  • RE: Split question
    ... >>first argument as a regular expression. ... it searches for the null string to split on. ... > The second one is if you include parentheses in your regex. ...
    (perl.beginners)
  • Re: Get regular expression
    ... own tree structure. ... Expression compares a string character-by character, ... regular expression solution, which was about as close as one could get to ... the structure of the hierarchy can be inferred by using ...
    (microsoft.public.dotnet.languages.csharp)