Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you handle ' and [  ] in Regex?

Posted on 2011-03-09
3
Medium Priority
?
197 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 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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