I was just trying to understand jQuery source of the white space trim REGEX and came across the following:
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
Now using a REGEX TOOL , i understood the following:
/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g
1st Alternative: ^[\s\uFEFF\xA0]+
^ assert position at start of the string
[\s\uFEFF\xA0]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\s match any white space character [\r\n\t\f ]
\uFEFF matches the character uFEFF literally (case sensitive)
\xA0 matches the character with position 0xA0 (160 decimal or 240 octal) in the character set
2nd Alternative: [\s\uFEFF\xA0]+$
[\s\uFEFF\xA0]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\s match any white space character [\r\n\t\f ]
\uFEFF matches the character uFEFF literally (case sensitive)
\xA0 matches the character with position 0xA0 (160 decimal or 240 octal) in the character set
$ assert position at end of the string
g modifier: global. All matches (don't return on first match)
The above description makes the REGEX very easy to understand, but still thinking about the implementation practically, a few things don't make sense , I.E.
uFEFF
why would a sting ever have this character and what does it have to do with white spaces ? And also what on earth is xA0
?
Can anybody explain ? you don't have to give the most detailed answer a short brief one will do.