473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with preg_match with capturing and back-reference

pt
I'm trying to detect and extract a quoted portion of a string. The
quote chars may be the usual quote, the "single" quote (apostrophe) or
the back-tick quote. For example:
$vl = "My O'Name";

if (preg_match ( '/(["\'\`])([^\\1]*)/' ) , $vl , $x ) { // found it }

The first parenthesized expression will capture the leading quote
(whatever it is). The second *SHOULD* capture everything up to, but
not including, the matching trailing quote. What I get is $x[1]
contains the quote (as expected), but $x[2] is everything up to AND
INCLUDING the trailing quote.

This is PHP 5.1.2 with PCRE 6.2 01-Aug-2005

Aug 18 '06 #1
1 2795
pt wrote:
I'm trying to detect and extract a quoted portion of a string. The
quote chars may be the usual quote, the "single" quote (apostrophe) or
the back-tick quote. For example:
$vl = "My O'Name";

if (preg_match ( '/(["\'\`])([^\\1]*)/' ) , $vl , $x ) { // found it }

The first parenthesized expression will capture the leading quote
(whatever it is). The second *SHOULD* capture everything up to, but
not including, the matching trailing quote. What I get is $x[1]
contains the quote (as expected), but $x[2] is everything up to AND
INCLUDING the trailing quote.

This is PHP 5.1.2 with PCRE 6.2 01-Aug-2005
I don't think you can use a back reference in a character class. Try
this pattern instead: /(["'`])(.*?)\1/.

Aug 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Harikumar G | last post by:
Friends, I have a C# console application for verifying a signature of an encrypted, this is done thru the Process.Startinfo method, My dos application for the decryption is gpg.exe (gnupgi) ...
1
by: Magnus | last post by:
I want to generate a report and display it as a pdf in a WebForm (RptForm). To generate the report I need to pass some (sometimes a lot of) parameters from a WebForm (WebForm1). The report looks...
1
by: DarthOptimus | last post by:
Hi, There is javascript code on my jsp to prevent double submission of a form: <SCRIPT type="text/javascript" language="JavaScript"> var firstSubmit = true; function isFirstSubmit() {
1
by: bharathbvb | last post by:
Hi, I am using a date picker control in my form. I have binded the control with a regular expression validator. When i type the date in the datepicker control it is getting validated. But when i...
4
by: Heinrich Wolf | last post by:
Hi all I have a history.back() problem with FF(2). IE works as expected, while FF does not. The multi frame website setup as a whole with a lot of frame content switching works flawlessly in...
0
by: =?Utf-8?B?QmlsbCBC?= | last post by:
I am having a problem where no data is being returned from an Axis web service. I can invoke the service just fine and it does not give any errors, but the data objects do not hold any data. If I...
4
by: shahidrasul | last post by:
hi in my project when i click on logout anchor it goes to logout page and my code in logout page is if (Session != null) { Session = null; Session.Abandon(); ...
2
viswammamilla
by: viswammamilla | last post by:
Hai i did one application ,its an intranet web application using asp.net and vb.net. Once user login into the application and did some task whenever user hits back button it will come back to one...
0
by: LTCCTL | last post by:
hi all, I have an application to send and recieve an SMS but my application is not catching the incoming message. can anyone tell what's wrong with the following code: import...
4
by: Ronald Ocampo | last post by:
Hi, I have a network of five PCs with 4 running Vista Home Basic with the other one running XP. I have an Access 2007 database system wherein the back end is installed in the public folder of one of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.