Regex: How to replace the content of a tag
-
hy. I want to math all the words that end with “!” from this tag:
<title>Why I love! you so much</title>In this case, I want to match the word
love!because has an!Now, I made this beautiful regex:
(?-s)(<title>)*\w+!(?!\w*;)(?=[^<]*</title>)Now, I want to use this regex, to replace in several .html files all those tags that has
!Basicaly, I want to delete them from these tag. I try to replace!wih an emptyspace, like so:Search:
(?-s)(<title>)*\w+!(?!\w*;)(?=[^<]*</title>)
Replace by:\1\2(LEAVE EMPTY)But doesn’t work. Can anyone help me?
-
After replace, My tag should loook like:
<title>Why I love you so much</title>(without!) -
Hello @vasile-caraus,
I think that your regex S/R is excessively complicated ! Why not trying this simple one :
SEARCH
(?i)(?<=\w)!(?=\x20)REPLACE
Leave EMPTYSo, this search regex would match any
!symbol, which is, both :-
Preceded by a word character, whatever its case, due to the
(?i)modifier -
Followed by a space character
and would be deleted, as the replacement zone is empty !
Cheers,
guy038
-
-
Search:
(?:\G(?!^)|<title>)[^<]*?\K\b!\BReplace by:
(leave a space)!
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