Regular Expression Replace on Notepad++ [duplicate] - regex

This question already has answers here:
Notepad++ v4.2.2. regular expressions to match and replace all text between two tags
(2 answers)
Closed 3 years ago.
I need a regular expression to replace the value in XML tags. I need to find * and replace it with XXXXX. I made an attempt to do this but its giving me "invalid regex".
<TAG>\('(.*?'\)</TAG>
// replace with:
<TAG>XXXXX</TAG>

I suspect that your actual starting content is something like this:
<TAG>some content here</TAG>
If you want to mask the content of such tags, you may try the following find and replace, in regex mode:
Find: <TAG>(.*?)</TAG>
Replace: <TAG>XXXXX</TAG>
Demo
Note that in general it is not desirable to manipulate nested content like XML/HTML using regex. But sometimes, e.g. when using tools like NPP, we are forced to do this. My answer should work fine assuming you are only targeting <TAG> elements which have no other children tags inside of them.

Related

Regex to pull out text between two strings [duplicate]

This question already has answers here:
Regex catch string between two strings, multiple lines
(4 answers)
Closed 2 years ago.
I'm trying to get the text from the [QOUTE] and [/QUOTE] but can seem to get it correctly. I'm just trying to pick it out and delete it. So I want to extract the text within as well as the actual HTML [QUOTE] parts. Just want to get rid of that entire code block via regex:
What I'm working with:
\[QUOTE(.+)|\[\/QUOTE]|
Text Example:
[QUOTE="", post: 1910681, member: 001""]
This is where the quote is located
[/QUOTE]
[URL unfurl=""true""]https://www.google.com[/URL]
Assuming those tags can't be nested, you can use the following regex with the single-line flag to match the tags and their content :
\[QUOTE\b.*?\[/QUOTE]
You can try it here.

Match rest of string with Regex in Notepad++ [duplicate]

This question already has answers here:
How to remove everything after a certain character? (notepad++)
(2 answers)
Closed 3 years ago.
I have the following json file:
[{"accountId":"fe1a8715-794b-4fd9-84df-ccbc7dd1c0c6","id":"9314c53324","state":"Processed","moderationState":"OK","reviewState":"None","privacyMode":"Private","processingProgress":"100%","failureCode":"None","failureMessage":"","externalId":null,"externalUrl":null,"metadata":null,"insights":{"version":"1.0.0.0","duration":"0:00:20.6","sourceLanguage":"en-US","sourceLanguages":["en-US"],"language":"en-US","languages":["en-US"],"labels":[{"id":1,"name":"outdoor","language":"en-US","instances":[{"confidence":0.9964,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.9981,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9966,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"},{"confidence":0.969,"adjustedStart":"0:00:17.067","adjustedEnd":"0:00:20.6","start":"0:00:17.067","end":"0:00:20.6"}]},{"id":2,"name":"mountain","referenceId":"geological formation/natural elevation/mountain","language":"en-US","instances":[{"confidence":0.9574,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.99,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9797,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"}]},{"id":3,"name":"snow","referenceId":"natural phenomenon/weather/snow","language":"en-US","instances":[{"confidence":0.9755,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.998,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.991,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"},{"confidence":0.9788,"adjustedStart":"0:00:19.2","adjustedEnd":"0:00:20.6","start":"0:00:19.2","end":"0:00:20.6"}]},{"id":4,"name":"nature","referenceId":"nature","language":"en-US","instances":[{"confidence":0.9946,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.9959,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9792,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"},{"confidence":0.8443,"adjustedStart":"0:00:17.067","adjustedEnd":"0:00:19.2","start":"0:00:17.067","end":"0:00:19.2"}]},{"id":5,"name":"valley","language":"en-US","instances":[{"confidence":0.8591,"adjustedStart":"0:00:00","adjustedEnd":"0:00:04.266","start":"0:00:00","end":"0:00:04.266"},{"confidence":0.9502,"adjustedStart":"0:00:04.267","adjustedEnd":"0:00:10.666","start":"0:00:04.267","end":"0:00:10.666"},{"confidence":0.9092,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:17.066","start":"0:00:10.667","end":"0:00:17.066"}]},{"id":6,"name":"canyon","referenceId":"geological formation/natural depression/canyon","language":"en-US","instances":[{"confidence":0.8353,"adjustedStart":"0:00:06.4","adjustedEnd":"0:00:08.533","start":"0:00:06.4","end":"0:00:08.533"}]},{"id":7,"name":"covered","language":"en-US","instances":[{"confidence":0.8697,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:14.933","start":"0:00:10.667","end":"0:00:14.933"}]}],"scenes":[{"id":1,"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"shots":[{"id":1,"tags":["Outdoor"],"keyFrames":[{"id":1,"instances":[{"thumbnailId":"a137ab2a-f250-4ace-a71f-8a158517863b","adjustedStart":"0:00:00.4","adjustedEnd":"0:00:00.467","start":"0:00:00.4","end":"0:00:00.467"}]},{"id":2,"instances":[{"thumbnailId":"52d41f10-20e7-40c4-9426-d2482fd6ec71","adjustedStart":"0:00:16.667","adjustedEnd":"0:00:16.734","start":"0:00:16.667","end":"0:00:16.734"}]}],"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"blocks":[{"id":0,"instances":[{"adjustedStart":"0:00:00","adjustedEnd":"0:00:20.6","start":"0:00:00","end":"0:00:20.6"}]}],"textualContentModeration":{"id":0,"bannedWordsCount":0,"bannedWordsRatio":0,"instances":[]},"statistics":{"correspondenceCount":0,"speakerTalkToListenRatio":{},"speakerLongestMonolog":{},"speakerNumberOfFragments":{},"speakerWordCount":{}}},"thumbnailId":"116bfb86-5a32-41a3-9fda-2417beb52a18","detectSourceLanguage":false,"languageAutoDetectMode":"None","sourceLanguage":"en-US","sourceLanguages":["en-US"],"language":"en-US","languages":["en-US"],"indexingPreset":"Default","linguisticModelId":"00000000-0000-0000-0000-000000000000","personModelId":"00000000-0000-0000-0000-000000000000","isAdult":false,"publishedUrl":"https://rodmandev.streaming.mediaservices.windows.net/0c4d34a3-4415-4f56-a4e5-7b34292eb72d/DJI_0043mp4.sil.ism/manifest(encryption=cbc)","publishedProxyUrl":null,"viewToken":"Bearer=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cm46bWljcm9zb2Z0OmF6dXJlOm1lZGlhc2VydmljZXM6Y29udGVudGtleWlkZW50aWZpZXIiOiIyNWI5OTRiOC03NzQyLTQ2MmUtOWExMy0zMTYwMzMwNWQzOGQiLCJuYmYiOjE1NzY1MDQxNTUsImV4cCI6MTU3NjU0NzQxNSwiaXNzIjoiaHR0cHM6Ly9icmVha2Rvd24ubWUiLCJhdWQiOiJCcmVha2Rvd25Vc2VyIn0.KAvVIh7dlFqbELqv2wwHJZocHonIXOZCvff20t3KWKg"}]
I'm trying to remove all the text except the words in quotes that come after "name".
In Notepad++, using the find and replace function, I searched for .+?name":"(.+?)" and replaced it with \1.
That returns the following result:
outdoor mountain snow nature valley canyon covered ,"language":"en-US","instances":[{"confidence":0.8697,"adjustedStart":"0:00:10.667","adjustedEnd":"0:00:14.933","start":"0:00:10.667","end":"0:00:14.933"}]}],"scenes":[{"id":1,"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"shots":[{"id":1,"tags":["Outdoor"],"keyFrames":[{"id":1,"instances":[{"thumbnailId":"a137ab2a-f250-4ace-a71f-8a158517863b","adjustedStart":"0:00:00.4","adjustedEnd":"0:00:00.467","start":"0:00:00.4","end":"0:00:00.467"}]},{"id":2,"instances":[{"thumbnailId":"52d41f10-20e7-40c4-9426-d2482fd6ec71","adjustedStart":"0:00:16.667","adjustedEnd":"0:00:16.734","start":"0:00:16.667","end":"0:00:16.734"}]}],"instances":[{"adjustedStart":"0:00:00.4","adjustedEnd":"0:00:20.6","start":"0:00:00.4","end":"0:00:20.6"}]}],"blocks":[{"id":0,"instances":[{"adjustedStart":"0:00:00","adjustedEnd":"0:00:20.6","start":"0:00:00","end":"0:00:20.6"}]}],"textualContentModeration":{"id":0,"bannedWordsCount":0,"bannedWordsRatio":0,"instances":[]},"statistics":{"correspondenceCount":0,"speakerTalkToListenRatio":{},"speakerLongestMonolog":{},"speakerNumberOfFragments":{},"speakerWordCount":{}}},"thumbnailId":"116bfb86-5a32-41a3-9fda-2417beb52a18","detectSourceLanguage":false,"languageAutoDetectMode":"None","sourceLanguage":"en-US","sourceLanguages":["en-US"],"language":"en-US","languages":["en-US"],"indexingPreset":"Default","linguisticModelId":"00000000-0000-0000-0000-000000000000","personModelId":"00000000-0000-0000-0000-000000000000","isAdult":false,"publishedUrl":"https://rodmandev.streaming.mediaservices.windows.net/0c4d34a3-4415-4f56-a4e5-7b34292eb72d/DJI_0043mp4.sil.ism/manifest(encryption=cbc)","publishedProxyUrl":null,"viewToken":"Bearer=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cm46bWljcm9zb2Z0OmF6dXJlOm1lZGlhc2VydmljZXM6Y29udGVudGtleWlkZW50aWZpZXIiOiIyNWI5OTRiOC03NzQyLTQ2MmUtOWExMy0zMTYwMzMwNWQzOGQiLCJuYmYiOjE1NzY1MDQxNTUsImV4cCI6MTU3NjU0NzQxNSwiaXNzIjoiaHR0cHM6Ly9icmVha2Rvd24ubWUiLCJhdWQiOiJCcmVha2Rvd25Vc2VyIn0.KAvVIh7dlFqbELqv2wwHJZocHonIXOZCvff20t3KWKg"}]
The problem is that I don't want to keep any text after covered.
I tried using .+?name":"(.+?)"(\S+) which removed some of the text I want to keep.
How do I fix this?
You should search using a pattern which targets the entire file:
Find: ^.*"name":"(.+?)".*$
Replace: $1
What is currently happening is that your pattern only targets everything up to the literal in quotes appearing after the key name. The content after that is not being replaced.
Demo

Notepad++ How to CUSTOM Regex this content [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I have below text:
_pranay_:pranay:104.144.219.145:3128
_ridhoo:rihdonk:104.144.224.242:3128
_shintna_10:shinhana:104.144.235.149:3128
_waled_jr_:ismail:104.144.241.222:3128
Which represent USER:PASS:PROXY
now I want to use a regular expression to remove the USER and PASS and keep the proxy.
Output like:
104.144.219.145:3128
104.144.224.242:3128
104.144.235.149:3128
104.144.241.222:3128
I've tried my best with failed attempts. am not that good in Regex. I wish somebody who can help me out. Thank you.
You can use https://regexr.com/ to play around with regex. For example, the expression below captures the part you want to remove:
([_a-zA-Z]+[0-9]*:)
Or, try the expression below to match the parts you want to keep;
([\d+\.]*:[0-9]{4})
As I'm no regex-expert, there might be better expressions available. But I recommend the link I provided to learn some regex.
You can maybe simply replace,
^[^:\r\n]*:[^:\r\n]*:
with an empty string.
Demo
If you wish to simplify/modify/explore the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.

Non-greedy regexp matching too much in pandoc-generated markdown file [duplicate]

This question already has answers here:
Regular expression to get text between square brackets including disparity?
(4 answers)
Closed 3 years ago.
The Problem
I'm trying to write a simple intermediary step in a Pandoc workflow. I have an original document in .docx which I'm converting to .md using the --track-changes switch (see Pandoc reader options for more information) to produce a markdown file which has MS word insertions/deletions/comments wrapped in span tags, e.g.
[Insertion text]{.insertion id="1" author="Jamie Bowman" date="2019-04-01T11:05:00Z"}
[Deletion text]{.deletion id="1" author="Jamie Bowman" date="2019-04-01T11:05:00Z"}
[Comment body]{.comment-start id="1" author="Jamie Bowman" date="2019-04-01T11:05:00Z"}[]{.comment-end id="1"}
I want to run a regexp find and replace on the markdown file which effectively 'accepts' insertions and deletions but leaves the comment spans. (This is so when I convert back to .docx, I have a clean .docx file with comments only.)
What I've tried
I have been able to accept all insertion spans and delete all deletion spans, but only when the body text does not carry across more than one line. My attempt at matching across new lines matches too much and I can't work out how to match the exact text only.
The following regexp matches almost all deletions which I can then replace with nothing:
Find: \[(.*?)\]{.deletion(.|\n)*?}
Replace:
Same for insertions which I can then use a backreference to retain the text but remove the span:
Find: \[(.*?)\]{.insertion(.|\n)*?}
Replace: $1
The patterns are matching too much, though, as you can see here.
Please let me know if anything is unclear. I've been working on this quite a bit today and it's difficult to explain the problem plainly! Thanks in advance.
The following regex should match the deletion fragments:
\[[^[]*?\]{\.deletion.*?}
The regex for the insertions are mostly the same, except you have to have a capturing group ([^[]*?\):
\[([^[]*?\)]{\.insertion.*?}

Regex to strip single comments and muti-line comments in Notepad++ [duplicate]

This question already has answers here:
How to match c-style block comments in Notepad++ with a regex?
(2 answers)
Closed 9 years ago.
the followings :
// comments
/******
comments
*******/
is it possible to have a regex for them ?
As the comments say, its not possible to strip comments in a correct way with regexes. But maybe its still enough for you to use the following regular expressions:
^\s*//.*$
/\*.*?\*/
You can do this with a simple hack. Select Extended mode and then replace all \r\n with a character/character-sequence that does not occur in your file and that which will match .*. Now change back to Regular Expression mode and apply the regular expression (given by morja) to do your replace. Now replace back the special character/character-sequence with \r\n.
#Mohammad Currently you cannot do this (match multiline) in Notepad++.
This is because matching newlines is possible in Extended search mode, and regular expressions are available in Regexp search mode.
You could however combine different steps and do what you want as pointed by other answers.
The easiest solution is not to use regex from Notepad++, you sould only export as rtf (plugins --> nppexport --> export to RTF) then open with Microsoft Word or other that support format searching, so with that feature you can search and replace the green values only.
I hope it helps.