Re: regex problem unresolved
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 10 May 2008 16:58:56 GMT
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
.
- References:
- regex problem unresolved
- From: Ela
- regex problem unresolved
- Prev by Date: Re: regex problem unresolved
- Next by Date: Re: Perl DBI Module: SQL query where there is space in field name
- Previous by thread: Re: regex problem unresolved
- Next by thread: Re: regex problem unresolved
- Index(es):
Relevant Pages
|