faqts : Computers : Programming : Languages : PHP : Common Problems : Regular Expressions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 7 people (86%) answered Yes
Recently 6 of 7 people (86%) answered Yes

Entry

How do I escape brackets in a regexp? I want to remove all but azAZ09_-[] from a string..

Aug 17th, 2002 15:28
Nate Weibley,


See if this is what you want...
<?php
$string='This is my cRa\'z^3 $tr|ng';
$string=eregi_replace("[^a-z0-9_\-\[\]]*",'',$string);
echo $string;
?> 
That will output:
ThisismycRazY3trng
If you want to keep spaces, add one before a-z.
Hope that helps,
--Nate
iamfast@tampabay.rr.com