D
D
Dmitry Kalinin2021-06-30 20:01:41
PHP
Dmitry Kalinin, 2021-06-30 20:01:41

How to make replacements in text that is not between characters/tags?

For example, there is some text:

"text text anchor text [special] text text text anchor text [/special] text text anchor text"

you need to find / replace all the words "anchor", but not the one that is inside the [special] tags [/special]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-06-30
@myrecs

preg_replace('#якорь|\[special\].*?\[/special\](*SKIP)(*F)#s', 'TXT', $str);

https://regex101.com/r/RGvDXI/2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question