November 22nd, 2011, 08:55 AM
Rookie: Partial Replacement
I tried out a lot of things now and didn't get it to work.
What I want to achieve is
<A HREF="#pgfId-697091" CLASS="footnote">1</A>
I do have other links in my source which have to stay unchanged.
I managed to get something like this to work, but it selects the 1 as well and I just don't know on how to call the replacement.
Can someone please help me?
Thanks in advance
November 22nd, 2011, 01:19 PM
Be as specific as possible.
<A HREF="#pgfId-\d+" CLASS="footnote">(\d+)</A>
November 23rd, 2011, 03:15 AM
ok, thanks for the answer!
Originally Posted by requinix
but http://regexpal.com/ shows me that this pattern would still match (and therefore?) replace the 1 as well.
Is that true?
Thanks in advance!
November 23rd, 2011, 01:28 PM
If you don't use the replacement string to put it back, yes.
Originally Posted by Alexander Odent
December 19th, 2011, 06:37 PM
requinix is right, but just to flesh out the answer. You need two expressions, one for the match, one for the replace.
For educational purposes, here is another candidate for the match:
Here is a candidate for the replace:
Bringing it all together in PHP, you would write something like:
Let me know if you need any more details.
$subject='the string you are trying to test';
$result = preg_replace('%(?i)<a href="#pgfid[^>]*?>([^<]*?)</a%m', '<sup>\1<sup>', $subject);