Easy Regex (when you know how... and I don't)

  • Thread starter The Plankmeister
  • Start date
T

The Plankmeister

Hi...

I hacked about for a bit and got this to work:

/^\s+/

So that it matches any whitespace characters at the start of the string. But
how can I modify it so that it matches strings made ONLY of whitespace?

P.
 
M

Martin Honnen

The said:
Hi...

I hacked about for a bit and got this to work:

/^\s+/

So that it matches any whitespace characters at the start of the string. But
how can I modify it so that it matches strings made ONLY of whitespace?

Whitespace from the beginning ^ to the end $:
/^\s+$/
That wouldn't allow empty strings so maybe you want
/^\s*$/
 
L

Lasse Reichstein Nielsen

The Plankmeister said:
/^\s+/

So that it matches any whitespace characters at the start of the string. But
how can I modify it so that it matches strings made ONLY of whitespace?

/^\s*$/

This matches strings that only have zero or more whitespace between
start and end of the string. If you don't want to include empty strings,
change the "*" to a "+".

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top