RegEx weirdness with CaseSensitive

I have a little code to see if a string contains 4 of the same chars in a row.
This works fine if case sensitive is not needed. But when needed, it still says it is a match.

The below example should say it did not found a match.

[code]dim r as new RegEx
r.SearchPattern = “([\pL\pN])\g1{3,}”

dim rxOptions as RegExOptions = r.Options
rxOptions.CaseSensitive = true

if r.Search( “abcdeffFf” ) isa RegExMatch then
MsgBox “found 4 of the same chars”
else
MsgBox “Not found”
end if[/code]

Whats wrong in this code?

Please try it with inline-options:

r.SearchPattern = "(?m-Usi)([\\pL\\pN])\\g1{3,}"

Does it work this way?

*More information about Inline-Options in Regular Expressions on the MSDN Library.

Thank you Sascha. That did the job.

BTW I still hate RegEx. :sunglasses:

You wouldn’t if you use RegExRx or RegExMagic :wink:

Don’t tell the others, but i just started RegExRx, pasted your Code, activated CaseSensitive Search and copied the native Xojo Code from within RegExRx. Then i searched the Web for informations about this “(?m-Usi)” stuff. :smiley:

There are a few such switches and you can use them at any place in the pattern, or in a particular group. Typically, you would use them at the start of the pattern as I did in RegExRX. The most common switches are:

  • i - case-insensitive
  • m - multi-line mode (treat target as multiple lines)
  • x - free-spacing
  • s - dot matches newline
  • U - ungreedy

You can combine switches in one statement, including negating them with a minus. For example:

(?i-Um)(?s)

means “case-insensitive, but not Ungreedy (so, greedy) and not multi-line mode (treat target as one line), then dot matches newline”.

This is also valid:

(?i)under(?-i)worked

(“under” is case-insensitive, but “worked” is case-sensitive)

As is this:

(?i)under(?-i:worked)

A great site for regular expression information and training:

http://www.regular-expressions.info

@Kem
You app is pretty cool. Still you do need to know some things about RegEx. I mean, it’s not self explanatory :slight_smile:

And yes … I still hate RegEx (but I know it is powerful and very handy). =)

Oh no, not self-explanatory at all. But I did what I could to help explain stuff (a little) within the app. For example, those mode switches are referenced under the Options BevelButton.

[quote=269058:@Christoph De Vocht]@Kem
You app is pretty cool. Still you do need to know some things about RegEx. I mean, it’s not self explanatory :slight_smile:

And yes … I still hate RegEx (but I know it is powerful and very handy). =)[/quote]

You will learn all you need to know by using/playing with RegExRx. And soon after, you will “love” RegEx :slight_smile:

This happened to me years ago with RegExMagic (and it’s predecessor) and again with RegExRx :smiley:

Everyone starts off hating regular expressions. Even me. :slight_smile: