Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to Match " | "

I am trying to use Java's useDelimiter method on it's Scanner class to do some simple parsing. Basically each line is a record delimited by " | ", so for example:

2 | John Doe
3 | Jane Doe
4 | Jackie Chan

The method takes as a parameter a regular expression for which to match for. Can someone please provide me with the regular expression that would match | (A vertical bar separated by one space on both sides).

Thanks, I would really appreciate it!

like image 789
Jorge Israel Peña Avatar asked Mar 04 '10 00:03

Jorge Israel Peña


People also ask

How do I match a specific character in regex?

Match any specific character in a setUse square brackets [] to match any characters in a set. Use \w to match any single alphanumeric character: 0-9 , a-z , A-Z , and _ (underscore). Use \d to match any single digit. Use \s to match any single whitespace character.

What is ?: In regex?

'a' (which in this case ?: is doing it is matching with a string but it is excluding whatever comes after it means it will match the string but not whitespace(taking into account match(numbers or strings) not additional things with them.)

What does the regular expression A to Z matches?

The regular expression [A-Z][a-z]* matches any sequence of letters that starts with an uppercase letter and is followed by zero or more lowercase letters.


1 Answers

" \| " 

would work, you need to escape quotes and the |

like image 170
adhanlon Avatar answered Oct 13 '22 22:10

adhanlon