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]
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.
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:
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.