negation - RE
am 11.09.2007 17:22:17 von fred78980
Case1
This is my RE to negate cer which is OK
negation of (cer)
(\w{0,10})(?
This take every word ending with er except word that end cer
Case2
and I use a similar RE to negate bcer
negation of (bcer)
(\w{0,10})(?
I tried (?
Case 3
negation of (b|c|d)er
(\w{0,10})(?
This RE is too long
Please help me with case 2 and 3.
Many thanks
Re: negation - RE
am 11.09.2007 18:24:00 von Ben Morrow
Quoth fred78980@yahoo.com:
> Case1
> This is my RE to negate cer which is OK
You will need to explain what you mean by 'negate'. It seems you have
some function which takes a regex as input and attempts to make a new
regex that matches some different set of data? You will need to explain
what forms of regex are possible input, and how you determine what you
want the output regex to match. The best way to do this is to post a
*short* example program *with input data* that demonstrates your
problem.
> negation of (cer)
> (\w{0,10})(?
> This take every word ending with er except word that end cer
OK, though it would probably be simpler to write it as
/ ( \w{0,9} [^\Wc] ) er /x
i.e. matching what you want to match, rather than matching a \w and then
making a look-behind assertion about it.
> Case2
> and I use a similar RE to negate bcer
> negation of (bcer)
> (\w{0,10})(?
> I tried (?
I think you are confused about how look-around assertions work. (It is
rather confusing.) They do not consume any of the matched string, so
/(?
If what you want is 'twelve-character words ending in "er" but not in
"bcer"', then it is the latter you want; since you say it is not
working, you will have to say what you expected it to match.
This is where look-behinds really are valuable. Matching something like
that 'by construction', while possible, is terribly messy.
> Case 3
> negation of (b|c|d)er
> (\w{0,10})(?
> This RE is too long
Huh? Too long for what? Perl is quite happy with it.
Ben