Solved

How do you handle ' and [  ] in Regex?

Posted on 2011-03-09
3
188 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 38

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
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 look for a specific file type in a local or remote server directory using PHP.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now