Is it possible to search and replace text without touching html tags?
-
Hi
I was wondering if we can search and replace text in a HTML file but not in the HTML tags only the text that appear when you load an HTML page in a browser?For example, say I want to replace the letter A by B in this line :
<A HREF=“url”>A B C </A>
Since the letter A is also in the tags, is it possible to only replace the letter A appearing outside the tags?
Thank you much for your help guys
-
Hello, @alfredodo1 and All
The regex S/R, below, would search for any
Aletter, whatever its case, inside the dots area (.) ONLY, even if divided in several lines, in the statement<A HREF=bla bla bla bla blah>..................</A>and replace it with the uppercase letterBSEARCH
(?si)(?:\G|<A HREF=.+?>)(?:(?!<|>).)*?\KAREPLACE
BNotes :
-
The part, to look for, is located after the
\K -
Of course you may use other tags , instead of “
a href=” !
Just test it with that text below :
<A HREF="https://www.w3schools.com/html/default.asp">Visit "W3Schools" to get the 'A B C' of HTML, JAVASCRIPT, PHP, XML, ASP,... !</A> <a href="https://www.w3schools.com/html/default.asp">Visit "W3Schools" to get the 'a b c' of HTML, JAVASCRIPT, PHP, XML, ASP,... !</a> <A href="https://www.w3schools.com/html/default.asp"> Visit "W3Schools" to get the 'A B C' of html, javascript, php , xml, asp,... ! </a>Best Regards,
guy038
-
-
Hi guy038 you really rock thank you so much for your help, that’s very kind from you. Your solution works wonder, thanks for this very detailed help !
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