Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-19-2002, 11:10 AM   #1
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
Reg Exp

what is the regular exp to match a string consisting only of
white spaces?
Old 09-19-2002, 11:26 AM   #2
Registered: Dec 2001
Location: Stockholm, Sweden
Distribution: Ubuntu, Kubuntu and Debian
Posts: 338

Rep: Reputation: 30
Is there really a regular expression for that?
In what language are you programming in?
Old 09-19-2002, 12:04 PM   #3
Registered: Apr 2002
Posts: 549

Original Poster
Rep: Reputation: 30
Re: Reg Exp

Originally posted by ugenn
what is the regular exp to match a string consisting only of
white spaces?
Javascript. Does it really matter what language I'm using?
Aren't regex syntax the same?
Old 09-19-2002, 12:22 PM   #4
LQ Addict
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
For instance, in perl regex processing supports \s to be used to match a whitespace, I really haven't used anything but perl for pattern matching and other text manipulations, so in perl it would look like
meaning to match exactly one or more consecutive whitespaces
Old 09-19-2002, 01:01 PM   #5
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
It should be the same, regardless of the language.. however, according to javascript's regexp's were created based on perl's regexp.

neo is right that \s will match whitespace.. the only thing missing is the fact that you asked for a regexp that would match a string that consists ONLY of whitespace, which means that the start/end line boundary's will need to be used. I'm not super familar with javascript, but here is my attempt:
function isWhiteSpacel(myString)_
  var inString = myString.match(/^\s*$/);
  if (inString) {
    alert("string '"+ myString + "' contains only whitespace")
Note that I used * instead of +, as neo suggested... this + means one or more, and * means zero or more, so this version will match even a blank string. I use something similar when parsing config files in perl.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Clarification needed in this reg exp/awk code mselvam Programming 3 07-09-2005 06:26 PM
Need REG EXP Help to remove line breaks webshark Programming 18 07-08-2005 05:31 PM
need clarification in this reg exp/awk code mselvam Linux - General 1 07-08-2005 04:57 PM
Lost Reg Exp editor button in Kmail linuxbeliever Linux - Software 0 05-03-2005 11:56 PM
prob with reg exp rajatgarg Programming 3 05-28-2004 10:21 AM

All times are GMT -5. The time now is 05:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration