Regular expression with pipe
It seems to me that | has a special meaning in regular expression world. I am using ruby and could not find much documentation on same.
http://rubular.com/regexes/11724 works.
http://rubular.com/regexes/11725 does not work. Why and what is th开发者_如何转开发e correct regex.
Use a delimiter to escape your characters:
/(\w+)\|(\w+)\|(\w+)/
In regular expressions certain characters have special meanings. For instance, the bar character "|" is used to represent that multiple patterns may match - basically it works as an OR operator. In order to use the literal character instead of the special meaning, you simply have to use a delimiter. Use "\|" instead of "|" for the literal character.
|
means boolean "or" in regex: http://en.wikipedia.org/wiki/Regular_expression
精彩评论