ivbtar
ivbtar

Reputation: 879

Matching exclamation mark in a string in java

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

Answers (2)

Alex Kovalenko
Alex Kovalenko

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

dammina
dammina

Reputation: 655

Use the following pattern.

^\s!

Upvotes: 2

Related Questions