Reputation:
I try to match a string among white spaces.
I just thought it's as simple as \S*
, but does not work
http://regex101.com/r/jC0uA5
What do I miss??
EDIT:
I also thought
It's as simple as.
\S.*\S
but this does match only more than 2 characters.
Upvotes: 0
Views: 48
Reputation: 6552
Simply do: \S+
I am assuming that you do not require whitespace around the string, but that you want to ignore it if it is there.
Your previous regular expression of \S*
was actually matching, but the first match returned was an empty string.
For clarification, do you wish to also match whitespace within the string, or is your meaning of "string" intended to include only non-whitespace?
Upvotes: 0
Reputation: 304
You almost had it...
*
matches zero or more characters.
Try \S+
Upvotes: 1