How do you handle ' and [ ] in Regex?

Experts,
How do you handle a ' and a [   ]  in Regex?  I am getting the following error:

Parse error: syntax error, unexpected ']' in /mnt/www.mywebsite.net/web/content/cats.php on line 60

Thanks for your help!
preg_match_all('%<a href=[']/applications/category/categories.asp?CatId=(.*?)['] class="subcategory">(.*?)</a><font color=[']#666666[']>%',$buf1,$matches101,PREG_SET_ORDER);

foreach ($matches101 as $val) {

$category_id=$val[1];
$subcategory=$val[2];

Open in new window

rlb1Asked:
Who is Participating?
 
ragnarok89Commented:
I believe you need a \ before any special characters, that wat the regex interprets them as part of the expression.

so instead of '

you would use \'
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
Backslash is the escape character
0
 
rlb1Author Commented:
Thanks!  I thought I had attempted that... but your solution worked!
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.