A
A
Alex Kichenko2015-11-22 15:25:56
PHP
Alex Kichenko, 2015-11-22 15:25:56

How to exclude search between two words in regular expression?

Not strong in regulars.
There is the following task:
Remove all characters enclosed in curly brackets (and the brackets themselves) from the string, but do not search for them between the words 'script' and '/script'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dtestyk, 2015-11-22
@dtestyk

All that comes to mind (in Javascript):
str='AIhfgfhhfOBI78789OABAB'
str.replace(/(I[^O]*O|A[^B]*B)/g, '__$1__')
.replace(/ __I[^O]*O__/g, '')
.replace(/__(A[^B]*B)__/g, '$1')
str='scripthjkk45{hfgfh}111hf/script7787777{78789}script/ script'
str.replace(/\/script/g, '►')
.replace(/(\{[^}]*\}|script[^►]*►)/g, '__$1__')
. replace(/__\{[^}]*\}__/g, '')
.replace(/__(script[^►]*►)__/g, '$1')
.replace(/►/g, '/script')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question