Connecting Tech Pros Worldwide Forums | Help | Site Map

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

The Plankmeister
Guest
 
Posts: n/a
#1: Jul 20 '05
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



Martin Honnen
Guest
 
Posts: n/a
#2: Jul 20 '05

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




The Plankmeister wrote:
[color=blue]
> 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?[/color]

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/

Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Jul 20 '05

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


"The Plankmeister" <plankmeister_NO_@_SPAM_hotmail.com> writes:
[color=blue]
> /^\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?[/color]

/^\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 - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Closed Thread