php/regex: How to replace part of a found pattern, but leaving the rest as it is? -


How can I replace a substring in a given pattern, but how can I leave it without leaving it?

(Edit: Actual case is more complicated than the example given below, I will have to face incidents within XML tags. That is why I want to use regex!) < / P>

We say that I want to send "Z" letter "X" letter within one word

I want

aaxaa aax xa

aazaa aaz za

Including "x" is not a problem, Such as:

[^ x \ S] ^ [^ \ s]

but changed to a normal preg_match full match Where I want anything in the pattern except "X" as it is.

Wich is the best way to complete it in PHP?

If your regex only matches the relevant part, then it should

But if you need regex to join it then there is no problem that it changes the whole match (like preg_replace ('/ x /', 'z', $ string) ).

  preg_replace ('/ (non-replacement) X (restofregex) /   ',' $ 1Z $ 2 ', $ string);  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -