Solved

How do you handle ' and [  ] in Regex?

Posted on 2011-03-09
3
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

617 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