Reputation: 879
I have a line " !". White space and !. Two character string. How can i match this line with java pattern match. I tried
"^\\s{1}[^\\s]+!"
but not working.
Upvotes: 1
Views: 9948
Reputation: 131
I think you can try this regex: \s!
You simply need to match two chars: space(\s
) and exclamation mark(!
).
In your variant you searching for three or more chars^\\s{1}
(1) [^\\s]
(2) +!
(3) - whitespace, one or more non-whitespace and exclamation mark. You don't need to set {1} for one char.
You can use this link in order to learn more about java patterns.
Upvotes: 1