So, I have this scenario in my php
code where I have the following string
This is an outside Example <p href="https://example.com"> This is a para Example</p><markup class="m"> this is a markup example</markup>
And I want to do a case-insensitive search for the word example
in this string, but
- I want my regex to ignore occurrence of example inside a tag attribute (which I am able to achieve)
- I want to ignore search inside the following
<markup ..> any content </markup>
entirely
What I have done till now is,
/(example)(?:[^<]*>)/i
This works fine and ignores the example within href
of p
tag,
now I have modified it for the <markup>
/(example)(?!([^<]*>)|(\<markup[^>]*>[^<]*<\/markup\>))/i
but this isn't working. you can see my work - https://regex101.com/r/e2XujN/1
What I want to achieve with this
I will be replacing the matched example
word, in the following way
- Suppose if i found
eXamPle
it will be replace by<markup>eXamPle</markup>
Example
will be replace by<markup>Example</markup>
and so on,
Note: Case of the pattern in the matched string and replace string is same