I need a pattern (java regexp) which matches if there is a comma after key or key is at the end of line. i.e it should match both of followings:
1. xxxkey,yyy
2. xxxkey
Ive tried [\\,$]
pattern but it doesn't work.
' \\$ ' This matches a string ending with a single backslash. The regexp contains two backslashes for escaping.
- a "dot" indicates any character. * - means "0 or more instances of the preceding regex token"
RegExp. prototype. global has the value true if the g flag was used; otherwise, false . The g flag indicates that the regular expression should be tested against all possible matches in a string.
The caret (^) is the starting anchor, and the dollar sign ($) is the end anchor.
$
inside a character class loses its special meaning. Use the following instead:
key(,|$)
If you don't need to know whether there was a comma, you can use a non-capturing group instead:
key(?:,|$)
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