Jump to content

extract data from web page


rupam_jaiswal

Recommended Posts

Yeah, my definition was a bit loose.

 

characters that are within the pattern need to be escaped (for the most part this is true.. but there are oddball exceptions.. but I digress)

 

I can't imagine a case where you don't have to escape delimiters in the pattern. Or were you talking about characters in general?

Link to comment
Share on other sites

Nope, I am talking about delimiter characters in a pattern :)

 

Consider the following for example:

 

$str = 'Some text... <_FOO_> some more text <_BAR_> and yet again some more!';
$str = preg_replace('<<_[^_]+_>>', '<_XX_>', $str); // note there is no need to escape < and > inside the delimiters in this scenario...
echo $str; // Output: Some text... <_XX_> some more text <_XX_> and yet again some more!

 

This is admittedly a stupid (and rare) example. But it shows that under some circumstances, it might not require escaping. In this case, there is a caveat... there has to be matching opening and closing < and > characters inside the < > delimiters.. if there is a mismatch, then you'll probably need to escape (otherwise you'll get either 'Unknown modifier' or 'No ending matching delimiter' warnings).

 

I personally advise against using opening / closing matching punctuation as delimiters (such as <...>, {...}, (...) or [....]). Too much confusion / trouble for what it's worth IMO.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.