laserlight;10887597 wrote:That sounds like a good reason, except that it means preferring a form that requires lookup (either mentally or by referring to a table) in order to avoid a mistake because a modifier is missing.
Agreed, this does mean some form of mental (or table lookup) to be sure. But in my case, I only bothered to memorize one character, and that is the space. For all other characters, I don't bother. I think another part of the reasoning behind the space is because of the \s notation. Obviously, this is a shorthand character class for many types of spaces.. (spaces, tabs, newlines, carriage returns, etc..).. and since I find it strange seeing a literal space, using \x20 does not encompass any of the other possible spaces by using \s. It is more immediately clear that it is a space (and especially not one intended for use with freespacing / commenting x modifier).
laserlight;10887597 wrote:Consider the pattern: '/a+/'. It is also conceivable that the + was intended to be a literal, in which case '/a\x2b/' would have avoided this mistake entirely. This would imply that one would need to have memorised the ASCII values of various other symbols which are significant in regex pattern syntax in order to be consistent.
Well, in my case as stated earlier, I only bothered to memorize one. In the case of using the plus as a literal instead of a +, there are options:
'/a[+]/' - since metacharacters lose their special meanings within a character class, this solves the issue of intending a + as a literal.
'/a\Q+\E/' also solves this issue, as obviously anything encapsulated within \Q \E is literal.
In my opinion, it is best to learn and understand the nuances of regular expressions and utilize those to your advantage then to start memorizing a complete slew of hex characters for the sake of literal translations (I'm not implying you don't know regex (as I know you do), just for people in general).