The following piece of code returns false when I believe it should return true. Can anyone tell me why? It's using java.util.regex.Pattern to parse the regex.
Pattern.compile("^\|:\|$".matcher("| |").matches();
The following piece of code returns false when I believe it should return true. Can anyone tell me why? It's using java.util.regex.Pattern to parse the regex.
Pattern.compile("^\|:\|$".matcher("| |").matches();
A \ in a string literal must be escaped as \\.
If you want to match anything in between, use .*, not :.
When you use the matches method in Java, you don't need to add the string boundaries ^ and $ as this function returns true only when it matches the whole string.
You seem to want
Pattern.compile("\\|.*\\|").matcher("| |").matches();