case-insensitive regexp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

case-insensitive regexp

Usman Bhatti
Hi,

Some regular expression engines include support for /i flag that makes the regexp case-insensitive.

In Pharo, regexp matcher can be setup to be case-insensitive (e.g. 'mypattern' asRegexIgnoringCase). But once a matcher is setup as case-senstive, can we provide a pattern to make its search case-insensitive using the /i (or a similar flag) in Pharo?

regards.

usman
Reply | Threaded
Open this post in threaded view
|

Re: case-insensitive regexp

Peter Uhnak
I do not think this is possible. The problem is that the Regex compiles (parses) the pattern so once it's created you would have to reparse it.
Theoretically speaking you could add ignoreCase accessors to RxMatcher but it is likely it would break things; or add method to RxMatcher that would return a new RxMatcher object with the proper settings.

Also note that regular expressions in Pharo are not the extended versions, where these things are usually available (alongside lookahead/lookbehind and other).
And personally I find the Regex library so awkward to use that I always opt for PetitParser.

~~~~
myParser := 'hello' asParser.
myParser matches: 'Hello'. "false"
myParser caseInsensitive matches: 'Hello'. "true"
~~~~

on the other hand there is no option to turn it back again. So if you regularly need to switch it back and forth it wouldn't be solution either.

Peter
Reply | Threaded
Open this post in threaded view
|

Re: case-insensitive regexp

Usman Bhatti
Thanks Peter.

On Thu, Jun 4, 2015 at 1:51 PM, Peter Uhnák <[hidden email]> wrote:
I do not think this is possible. The problem is that the Regex compiles (parses) the pattern so once it's created you would have to reparse it.
Theoretically speaking you could add ignoreCase accessors to RxMatcher but it is likely it would break things; or add method to RxMatcher that would return a new RxMatcher object with the proper settings.

Also note that regular expressions in Pharo are not the extended versions, where these things are usually available (alongside lookahead/lookbehind and other).
And personally I find the Regex library so awkward to use that I always opt for PetitParser.

~~~~
myParser := 'hello' asParser.
myParser matches: 'Hello'. "false"
myParser caseInsensitive matches: 'Hello'. "true"
~~~~

on the other hand there is no option to turn it back again. So if you regularly need to switch it back and forth it wouldn't be solution either.

Peter