Regular Expression Qestion - Reg Ex Question

Howdy!

Thanks for taking a look at this.  Can anyone tell me why this regular expression is removing spaces?  I think I've been staring at it for too long or something.

$myvar = preg_replace("/[^a-z\d.,-]/i", "", $myvar);

Thanks in advance!

ike1492
ike1492Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
yes, because the regular expression does removes all that is NOT alpha, decimal, dot, comma, dash.
if you don't want spaces to be removed, you have to add the space into the first part of the expression
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in code:

$myvar = preg_replace("/[^a-z\d\s.,-]/i", "", $myvar);
0
 
ike1492Author Commented:
Glad it wasn't a snake! thanks very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.