Are the following two regular expressions functionally equivalent? I ask because I get different results when I interchange them so I guess I know the answer is that they are not equivalent. However, I don't understand why.
(,|$)
and
[,$]
I am basically looking for a comma or the end-of-line.
The first one means a comma or end_of_line
The second means a comma or a dollar sign
Generaly special characters inside a class lose their special meaning.
So, for your question:
I am basically looking for a comma or the end-of-line.
Use the first one (,|$)
I think that when you put $ into bracket it is considered like the dollar char and not the end of line
you will found more information here : http://www.regular-expressions.info/charclass.html
extract :
Metacharacters Inside Character Classes
Note that the only special characters or metacharacters inside a character class are the closing bracket (]), the backslash (), the caret (^) and the hyphen (-). The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash. To search for a star or plus, use [+*]. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With