robinnnnn
robinnnnn

Reputation: 1735

Regular expression to match any string within brackets *but without whitespace*

If I have a string like so: <Hello> < World> I would like to match Hello but ignore World due to the whitespace.

So far I'm using this, /\<(.*?)\>/g but this returns both Hello and World. I would like to ignore any in-bracket words that contain any whitespace at all.

Upvotes: 0

Views: 79

Answers (2)

dbosky
dbosky

Reputation: 1641

Using PCRE:

/<(\w+)>/g

Check Live Demo at regex101

Upvotes: 1

Amit
Amit

Reputation: 46323

\S is the qualifier for non-whitespace character. Use this:

/\<(\S*?)\>/g

Upvotes: 0

Related Questions