0

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.

http://regex101.com/r/zD4vN8

\S.*\S

but this does match only more than 2 characters.

2 Answers 2

1

You almost had it... * matches zero or more characters. Try \S+

Sign up to request clarification or add additional context in comments.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.