Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
155
rated 0 times [  160] [ 5]  / answers: 1 / hits: 37751  / 15 Years ago, wed, july 22, 2009, 12:00:00

I am looking for a javascript regex for whitespace.
I am checking several different string in a loop and I need to locate the strings that have the big white space in them.



The white space string is built in a loop, like this...



please read this code as var whitespace =   then the loop just concats more non breaking spaces on it.



var whitespace =  

for (var x = 0; x < 20; x++) {
whitespace += &nbsp;
}


then it is used later on in a string concat.



sometext += whitespace + someData;


I need to identify the strings that contain whitespace (20 spaces).



Or should I just be doing a contains(whitespace) or something similar.



Any help is appreciated.



Cheers,
~ck in San Diego


More From » regex

 Answers
22

If you have defined whitespace as 20 spaces, you can do



var input = whitespace + someData;
if(input.indexOf(whitespace) != -1)
{
//input contains whitespace.
}


There is no need to use regex when you can do without it.


[#99073] Saturday, July 18, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leog

Total Points: 225
Total Questions: 113
Total Answers: 118

Location: Oman
Member since Wed, Apr 12, 2023
6 Months ago
;