dunbarx wrote: Tue Jun 09, 2026 2:04 pm
The string and regularExpression are always case-sensitive, regardless of the setting of the caseSensitive property. (
That is what Richmond was on about. Do I still misunderstand?
Edited my response as there was an issue with my regex testing stack that meant the flags (?msiU) were always added - good exercise to make me fix this.
Back to your comment:
Case sensitive is always the defaut, because
regex is case sensitive by default and the
only reason reason for matchText() is to bring regex to LiveCode. It makes little sense to produce a regex tool that uses other scripting languages to modify its regex behind the scenes.
Regex is designed as a pattern matching tool - matching any text that fits a pattern. One would want to define that pattern strictly, but this means part of the pattern is defined in OXT script, and part of it in regex, which is not sane. This move makes me think OXT is adapting it as a string literal search, which is at best weird, when the language has many other tools for exactly this (offset, find, etc).
Example usage: If you have the string:
the regex
will match the second line, "hello world" - ie case sensitive.
To make it case-
insensitive, one would use the flag i, in other words to match "Hello World" (remembering that PCRE regex only returns the 1st match), the regex would need to include the case-insensitive flag
(?i):
I don't understand why one wouldn't use regex syntax to write regex - which was my point. MatchText() is there to use regex.
Modifying the IDE to add the "(?i)" flag in OXT script via the CaseSensitive property means that using the actual regex anywhere else might fail because the regex itself wouldn't include this when it would be expected to.
Madness from a programming point of view...
-------------------------------------------
Explanation of the regex used above:
- The terminal group (?:\R) is a non-capturing group - terminates the match without including it - (?: ) is a non-capturing group. \R is any kind of line ending (CR, LF, CRLF).
- The capturing group that is returned by MatchText is (hel.+) - ie the letters "hel", wildcard char "." and + denotes "one or more of the previous char", in this case the wildcard). Each capture group is in parentheses (...) without the ? or ?: modifiers.
- Flags are set at the start with (?msixU) - where each letter after the '? is a flag. Flags are in the form (?...). Case Insensitive flag is (?i).
.
My top tip for testing regex is to use
https://regex101.com. Always test your regex there first to make sure it works.
The only adaptations to bring whatever works there to livecode:
- There is no 'global' flag in PCRE regex, so ensure you switch of the g (global) flag. Global is nice because it matches all occurrences, sadly LiveCode's choice of PCRE regex only returns the first match, so switch off /g in regex101.com.
- In JS, the flags are appended after the regex in the form /<regex text>/msixU, whereas in PCRE these are prepended and the capture group(s) to return in matchText are in parentheses, in the form (?msixU)(<regex text>), where m, s, i, x, U are the commonest flags can be used alone or in combination.
Regex basics don't take long to learn. I wrote a primer:
https://github.com/stam66/regexPrimerForLivecode/wiki
Regex101.com includes an incredibly handy searchable reference as well.