tags:

views:

79

answers:

3

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 the correct regex.

+5  A: 

Use a delimiter to escape your characters:

/(\w+)\|(\w+)\|(\w+)/
tadman
+2  A: 

| means boolean "or" in regex: http://en.wikipedia.org/wiki/Regular_expression

Leventix
+3  A: 

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.

Swiss