Forum Moderators: coopster
say I have this pattern scattered a number of times througout the text, the "TEXT1" and "TEXT2" not being all the same and can contain such things as numbers, hypens, and spaces etc:
yyyTEXT1¦TEXT2yyy
what I want to end up with is:
yyyTEXT2yyy
In short, get rid of the first word and the "¦" that separates them. How might this be done using preg_replace?
Thank you in advance!
[edited by: rfontaine at 2:59 pm (utc) on Sep. 22, 2004]
Assumptions:
- "yyy" never appears in TEXT2
- you want everything before and after the "yyyTEXT1¦TEXT2yyy"
Note that this forum transforms pipes (¦) so you can't copy and paste this - you must delete and then retype the pipe.
Tom
Anyway, that's a better solution, except that you need to escape the pipe (I'm assuming that it's a pipe and it's the forum software that transformed it into a broken pipe)
echo_pre(preg_replace('/(yyy)[^\¦]+\¦/i','$1',$str));
echo_pre(preg_replace('/(yyy)[^\¦]+\¦(.*?yyy)/i','$1$2',$str));
Thanks Guardian,
Tom
I've noticed that you've been posting a ton of questions about regular expressions over the past week. I've replied to a couple of them myself.
Now, I'm just too curious. What are you trying to accomplish? Is this some kind of Web data mining? If so, I could suggest an easier way to do things. Just let us know what it is your doing, if it's legal LOL.
Cheers,
Jeff