|
Daniel_Draco Newbie
Joined: 08 Aug 2009 Posts: 8
|
Posted: Mon Jun 17, 2013 10:33 pm
Regex Case Sensitivity |
I have a need to remove all non-capitalized words from a list of words. As part of this I am using a regex to recognize which words begin with a capital letter -- and this is where it's failing. The problem can be demonstrated by inputting:
Code: |
#say %regex("thisislowercase","[A-Z]\w+") |
For me, this yields 1, indicating that a match was found, when it definitely should not; the [A-Z] should only match a capital letter. Is this issue unique to me? Is there any way to fix it?
|
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Tue Jun 18, 2013 2:00 am |
CMUD has the case insensitive option on by default. You can use (?-i) in your pattern to turn it off.
|
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Tue Jun 18, 2013 2:55 am |
It seems that the default for CMUD regex is case insensitivity. Doing it this way works:
Code: |
#SAY %regex("thisislowercase","(?-i)[A-Z]\w+")
|
(?-i) turns case sensitivity on. |
|
_________________ Sic itur ad astra. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Tue Jun 18, 2013 3:46 am |
Umm... I thought I just said exactly that?
|
|
|
|
Daniel_Draco Newbie
Joined: 08 Aug 2009 Posts: 8
|
Posted: Tue Jun 18, 2013 5:43 am |
Aha, that worked, thanks. This doesn't appear to be anywhere in the documentation, for some reason -- in fact, the documentation of #REGEX implies that it is case sensitive by default.
|
|
|
|
Moab Beginner
Joined: 02 Aug 2008 Posts: 25
|
Posted: Tue Jun 18, 2013 5:10 pm |
Just ran into this myself.
Thanks! |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Wed Jun 19, 2013 5:19 pm |
Probably because CMUD doesn't have any extensive documentation on regular expressions. There's plenty of sites for that.
|
|
|
|
|
|