Solved

How do you handle ' and [  ] in Regex?

Posted on 2011-03-09
3
191 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:rlb1
3 Comments
 
LVL 8

Accepted Solution

by:
ragnarok89 earned 250 total points
ID: 35084940
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
 
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 250 total points
ID: 35084943
Backslash is the escape character
0
 

Author Closing Comment

by:rlb1
ID: 35084990
Thanks!  I thought I had attempted that... but your solution worked!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question