Anyone know how to test an entire String for a match using Java regex?
I would like to search a String
for an entire match. In other words, if String s = "I am coding"
, and I type in that I am searching for "am"
nothing should get returned. I need the exact String in order to get a match. In other words, I would have to type in"I am coding"
exactly in order for a match to be returned. 开发者_高级运维
I need the regex pattern for this, since I am using RowFiler.regexFilter(...)
.
Have you tried this: ^I am coding$
?
The regex, if it doesn't contain characters to escape is as what you are looking for: any character maches for itself and two next characters means concatenation. So, in this case, "\AI am coding\z"
is your answer..
On the Regex side of things:
using the start of string anchor ^
and end of string anchor $
at the beginning and the end of your search pattern (respectively) to ensure that the search string doesn't contain anything else (i.e. it equals the pattern you're trying to match. Regex:
^I am Coding$
Ref: http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm
精彩评论