Search and replace question
-
Could you please help me with the following search-and-replace problem I am having?
I am editing an html file and need to delete many of the hyperlinks.
Here is the data I currently have (“before” data):
<a name="pgfId-659225"></a><a name="TMS AEO alt_remote_control"></a><a name="alt_remote_control"></a><a name="TMS alt_remote_control"></a>alt_remote_control</h6>Here is how I would like that data to look (“after” data):
<a name="pgfId-659225"></a><a name="alt_remote_control"></a><a name="TMS alt_remote_control"></a>alt_remote_control</h6>In other words, I want to delete the hyperlink whose name begins with “TMS AEO” and leave the other hyperlinks on that line intact.
To accomplish this, I have tried using the following Find/Replace expressions and settings
Find What =
<a name="TMS AEO .+</a>
Replace With = ``
Search Mode = REGULAR EXPRESSION
Dot Matches Newline = NOT CHECKEDUnfortunately, this did not produce the output I desired, and I’m not sure why. It ended up selecting all of the hyperlinks on that line up to the last “</a>”. Could you please help me understand what went wrong and help me find the solution?
-
@Tom-Dirks said in Search and replace question:
<a name="TMS AEO .+</a>Unfortunately, this did not produce the output I desired, and I’m not sure why. It ended up selecting all of the hyperlinks on that line up to the last “</a>”
So very close! Great job
The
.+is greedy, so it will match as many single characters as it can, which can include single characters that make up the hyperlinks between. If you make it non-greedy by adding a?to make that.+?, it will stop the match at the first</a>instead of the last</a>: Thus,<a name="TMS AEO .+?</a>should work for you-—
Useful References
-
@PeterJones That worked! Thank you very much.
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