Friday, 15 March 2013

How do dashes work in regex? -


I'm curious to know which characters are included in the algorithm, in a regex when - ...

  Example: [a-zA-Z0- 9]   

This matches any of the characters in any position Is, z to one, and 0 to 9 numbers

I originally thought that they were used like macros, for example, az translation a, b, c, d, e etc. But when I saw one in the following,

  text.tr ('a-za-z1-90', 'â €? ¶-â ????? - a - ??? ?? â ?? -Ã⠀ šÃ, · ÃÆ'à ¢ â,¬Å¡Ãƒâ € šÃ, ·?   < P> My paradigm on regex has changed completely, because these characters are not your typical characters, so how did Heck do it correctly, I thought to myself.  

My theory is that - literally means

Any ASCII value between left character, and right character (eg. [97-122])

Can anyone confirm that my theory is correct? Does the Reazx pattern actually use the character code to calculate between any character?

In addition, if it is correct, you can match a regex like you,

  Az   

because A is 65 , and z is 122 therefore theoretically, all the characters should match between those values .

(bold is mine):

A range of characters The syntax for specifying is as follows:

  [firstCharacter-lastCharacter]   

Where the first master Code> is the range that starts and the last sector is the range that ends the class A character The first character in the range series, a hyphen ( - < / Code>), and then the last character in the series Specified is a series of characters defined by . If they have adjacent unicode code points, then two characters are consistent.

So your perception is correct, but the effect is really broad: Unicode character code, not just ASCII.

No comments:

Post a Comment