Match and replace specific word between two tag symbol
-
Hi,
I’m trying to rename a specific word within tag symbol and i just cant figure it out and already tried looking on examples but still I’m stuck. Kindly please help.Example: I want to rename the word “LOCAL” to “SPACE” but only within <div>xx…xx</div>.
<div>xxMETADATA-LOCALX1-ROOMG1-LEVELB2xx</div>
<div class=“metadata”>METADATA-LOCALX1-ROOMG1-LEVELB2</div>Expected Result:
<div>xxMETADATA-LOCALX1-SPACEG1-LEVELB2xx</div>
<div class=“metadata”>METADATA-LOCALX1-ROOMG1-LEVELB2</div>Thank you very much.
-
Hello, @jade-owen,
I’m a bit perplexed ! Indeed, from your example, it looks as you would change the upper-case string
ROOMwith the upper-case stringSPACE, when within a<div>.......</div>range, only… and NOT theLOCALstring !!If it’s really what you want, the regex, below, should do the job, strictly !
SEARCH
(?-is)(<div>.*?LOCAL..-)(.*?)(?=..-.*?</div>)REPLACE
\1SPACEOPTIONS Tick the
Wrap aroundandRegular expressionoptionsACTION Click, once, on the
Replace Allbutton, or several times on theReplacebuttonBest Regards,
guy038
P.S. :
Generally speaking, it’s important to point out that regexes are very dependent of the text they are applying against ! Even a simple additional space character, in a text, can break out matches detection of a well-formed regex !
So, I advice everyone, which wants a specific search/replacement, to carefully describe :
-
The searched text which must be matched
-
The replacement text which will be inserted, instead
Doing this way should help out to build the right regex(es) and assures you to get a quicker solution, too ;-))
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login