Jump to content


Photo

Preg match


  • Please log in to reply
2 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 15 August 2006 - 04:09 PM

Could anyone demonstrate to me a preg match that detects if the subject contains only spaces?

I can't work it out myself.

Thanks for any help.

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 15 August 2006 - 04:13 PM

<pre>
<?php

	$string = '    ';
	echo 'All spaces? ';
	echo preg_match('/^\x20+$/', $string) ? 'Yes' : 'No' ;
	
 ?>
</pre>

If you're looking for blank lines, change the + to *, and \x20 to \s. \s is more commonly used to represent any kind of whitespace, not only spaces.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 15 August 2006 - 04:18 PM

Works perfectly, thank you very much.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users