0

this is a part of my code to find "1" in the p,span,a and some other tags, also between "{changenumber}" and "{/changenumber}" anywhere and then replace it with "2":

code for find:

(((<(p|span|a|li|ul|br|/br|tr|td)[^>]*>)|(\{changenumber\}))[^<|(\{/changenumber\})]*)1(.*(<|(\{/changenumber\})))

and code for replace:

\12\7

but there is a problem it exclude in [^<|(\{/changenumber\})] all the characters of this phrase: "{","c","h","a",etc

I try \b\{/changenumber\}\b and (?!...) but I can't!

How it can exclude the exact phrase "{changenumber}"?!


In a simpler way:

when we write [^abc]+ it excludes "a" and "b" and "c" but what's the way if we want it to exclude the exact "abc"?!

[^(abc)]+ doesn't work

[^\babc\b]+ doesn't work

(?!abc) doesn't work

(?!\babc\b) deosn't work

...


Its language is English

I use regex because it's the way to replace in the rereplacer component in joomla

No way?!!!

Ru Alv
  • 21
  • 2

1 Answers1

0

when we write [^abc]+ it excludes "a" and "b" and "c" but what's the way if we want it to exclude the exact "abc"?!

[^(abc)]+ doesn't work

[^\babc\b]+ doesn't work

(?!abc) doesn't work

That's false; negative lookahead works; if it seems to do not, the usage is at fault.

but there is a problem: it excludes in [^<|(\{/changenumber\})] all the characters of this phrase — "{", "c", "h", "a", etc.

Instead of

[^<|(\{/changenumber\})]

write

((?!\{/changenumber\})[^<])

— i. e., place the lookahead in front of the negated set.

Besides, you should make the .* non-greedy by replacing it with .*?.

Armali
  • 18,255
  • 14
  • 57
  • 171