By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,314 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.514 / Virus Database: 312 - Release Date: 28/08/2003
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


The Plankmeister wrote:
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*$/

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
"The Plankmeister" <plankmeister_NO_@_SPAM_hotmail.com> writes:
/^\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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.