LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 09-19-2002, 11:10 AM   #1
ugenn
Member
 
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
Ztyx
Member
 
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
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Original Poster
Rep: Reputation: 30
Re: Reg Exp

Quote:
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
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
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
\s+
meaning to match exactly one or more consecutive whitespaces
 
Old 09-19-2002, 01:01 PM   #5
TheLinuxDuck
Member
 
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 http://www.webreference.com/js/column5/ 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:
Code:
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.
 
  


Reply


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 11:01 AM.

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