Simple Regex wont work!!! Why?

A

Ali Eghtebas

Hi,

Why isn't this working? What's wrong with it? Am I missing something here?
Why this pattern wont match the string "cc".
Pattern: [^a].|.[^b] (This should match anything except "ab"
String: cc

While this will: [^a]c|c[^b]

Isn't a . supposed to match everything except \n unless modified by
SingleLine option?
 
J

Jason Evans

Hi there.

Try this

[^A|a].|.[^B|b]

I'm not sure how it works, but I tested it in a RegEx Workbench
utility that I have. It seems to work fine.

Hope this helps.

Jas.
 
A

Ali Eghtebas

Hi,

Well, this isn't what I want. E.g. your expression won't match the string
"ad".
I've tested some more expressions and I think this must be a bug in RegEx.
I think the bug occurs when having a ^ in brackets in the first part and
then
right after the | having a . or \w or any other Character class.
To explain by example look at the pattern below:
[^a].|\w[^b] will not match anything except any string starting with a "b"
e.g. "bu", "ba", "bc", etc. This is very strange!!!
While the pattern [^a].|[a-zA-Z_0-9][^b] which is exactly the same
pattern (\w = [a-zA-Z_0-9]) will work as it should, i.e. it matches
anything but "ab".

Please someone confirm if this is a bug!
 
A

Ali Eghtebas

Hi Chris,

For some strange reason that I can't comprehend, it returns True as you say
if IgnoreCase option is set on.
 
A

Ali Eghtebas

Forgot to mention that then "AB" is also excluded while we only want to
exclude "ab".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top