/    Sign up×
Community /Pin to ProfileBookmark

regex find, process and replace

hi all.

I have a problem that I think cn be solved with a bit of regex code, only I do not know enough to work this one out

example:
I have a string something like:

[CODE] <p><x>yz</x>someRandomText</p><p>moreTextThenAnother<x>yz</x>thenEvenMoreText</><p>rinseAndRepeat</p>[/CODE]

I need to search through the string , extract the yz do some stuff to it and then put it back between the x tages, so the string ends up like

[CODE] <p><x>qyzq</x>someRandomText</p><p>moreTextThenAnother<x>qyzq</x>thenEvenMoreText</><p>rinseAndRepeat</p>[/CODE]

does anyone know how I would do this? thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tastroSep 21.2011 — echo preg_replace("@(<x>)(yz)(</x>)@ism",'$1q$2q$3','<p><x>yz</x>someRandomText</p><p>moreTextThenAnother<x>yz</x>thenEvenMoreText</><p>rinseAndRepeat</p>');

also insert here what you want instead of the two qq in $1q$2q$3
Copy linkTweet thisAlerts:
@fideltfgauthorSep 21.2011 — echo preg_replace("@(<x>)(yz)(</x>)@ism",'$1q$2q$3','<p><x>yz</x>someRandomText</p><p>moreTextThenAnother<x>yz</x>thenEvenMoreText</><p>rinseAndRepeat</p>');

also insert here what you want instead of the two qq in $1q$2q$3[/QUOTE]

I'm not sure this is going to work. the <x>yz</x> may some times be <x>abc</x>, an unknown value, so it needs to find , processes and replace what is between the <x> tags , will this do that or does it just search for a set value?
×

Success!

Help @fideltfg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...