REQ: regex "\s" to match  

Propose new features and changes
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

REQ: regex "\s" to match  

30 May 2019, 12:30

i just beat my head against a wall trying to figure out why my regex wasn't working, only to find out that my string had a non-breaking space character (chr160) instead of a normal space char (chr32). why doen'nt \s pick that up?

awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: REQ: regex "\s" to match  

30 May 2019, 13:14

https://regex101.com/r/Y8hxYZ/1
I don't think this behavior is unique to AHK. You may have to take it up with the authors of the RegEx library that AHK uses.

Edit: you can use \h instead of \s
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: REQ: regex "\s" to match  

30 May 2019, 13:29

its unique to pcre:
For compatibility with Perl, \s did not used to match the VT character (code 11), which made it different from the the POSIX "space" class. However, Perl added VT at release 5.18, and PCRE followed suit at release 8.34. The default \s characters are now HT (9), LF (10), VT (11), FF (12), CR (13), and space (32), which are defined as white space in the "C" locale. This list may vary if locale-specific matching is taking place. For example, in some locales the "non-breaking space" character (\xA0) is recognized as white space, and in others the VT character is not.
...
By default, characters whose code points are greater than 127 never match \d, \s, or \w, and always match \D, \S, and \W, although this may vary for characters in the range 128-255 when locale-specific matching is happening. These escape sequences retain their original meanings from before Unicode support was available, mainly for efficiency reasons. If PCRE is compiled with Unicode property support, and the PCRE_UCP option is set, the behaviour is changed so that Unicode properties are used to determine character types, as follows:
\d any character that matches \p{Nd} (decimal digit)
\s any character that matches \p{Z} or \h or \v
\w any character that matches \p{L} or \p{N}, plus underscore


The upper case escapes match the inverse sets of characters. Note that \d matches only decimal digits, whereas \w matches any Unicode digit, as well as any Unicode letter, and underscore. Note also that PCRE_UCP affects \b, and \B because they are defined in terms of \w and \W. Matching these sequences is noticeably slower when PCRE_UCP is set.
The sequences \h, \H, \v, and \V are features that were added to Perl at release 5.10. In contrast to the other sequences, which match only ASCII characters by default, these always match certain high-valued code points, whether or not PCRE_UCP is set. The horizontal space characters are:
U+0009 Horizontal tab (HT)
U+0020 Space
U+00A0 Non-break space
U+1680 Ogham space mark
U+180E Mongolian vowel separator
U+2000 En quad
U+2001 Em quad
U+2002 En space
U+2003 Em space
U+2004 Three-per-em space
U+2005 Four-per-em space
U+2006 Six-per-em space
U+2007 Figure space
U+2008 Punctuation space
U+2009 Thin space
U+200A Hair space
U+202F Narrow no-break space
U+205F Medium mathematical space
U+3000 Ideographic space


The vertical space characters are:
U+000A Linefeed (LF)
U+000B Vertical tab (VT)
U+000C Form feed (FF)
U+000D Carriage return (CR)
U+0085 Next line (NEL)
U+2028 Line separator
U+2029 Paragraph separator
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: REQ: regex "\s" to match  

30 May 2019, 21:05

thank you guys. that explains it. i probably won't use \h but rather just [  ] (that is just a char class of the two different spaces chr32 and chr160)


Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 26 guests