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!
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.
'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.)
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.
" \| "
would work, you need to escape quotes and the |
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