Notepad++ replace between .dodo? to </dada> - regex

hey guys my regex skills suck and was looking for some help. I am using Notepad++ and am looking to easily replace everything between the following
example:
.dodo?ReplaceMe</dada>
Its in many lines i need to replace often so rather than hunting hightlighting and replacing i was hoping to score an easyier regex method that will save me time. The replace can include question mark if it makes it easier. Thanks in advance

You can match your pattern using \.dodo\?([^<]*)<\/dada>.
\.dodo\? matches .dodo? - you need to escape the . and ??
([^<]*) matches all characters aren't a <, ReplaceMe in this case, in a matching group
<\/dada> matches </dada> - you need to escape the /
View it in action here: https://regex101.com/r/bM2wE6/1

Use lookarounds:
(?<=\.dodo\?).*?(?=<\/dada>)
See it in action

Related

Regex to remove a whole phrase from the match

I am trying to remove a whole phrase from my regex(PCRE) matches
if given the following strings
test:test2:test3:test4:test5:1.0.department
test:test2:test3:test4:test5:1.0.foo.0.bar
user.0.display
"test:test2:test3:test4:test5:1.0".division
I want to write regex that will return:
.department
.foo.0.bar
user.0.display
.division
Now I thought a good way to do this would be to match everything and then remove test:test2:test3:test4:test5:1.0 and "test:test2:test3:test4:test5:1.0" but I am struggling to do this
I tried the following
\b(?!(test:test2:test3:test4:test5:1\.0)|("test:test2:test3:test4:test5:1\.0"))\b.*
but this seems to just remove the first tests from each and thats all. Could anyone help on where I am going wrong or a better approach maybe?
I suggest searching for the following pattern:
"?test:test2:test3:test4:test5:1\.0"?
and replacing with an empty string. See the regex demo and the regex graph:
The quotation marks on both ends are made optional with a ? (1 or 0 times) quantifier.

Regex to find the last underscore and all text that follows it

My sample text would be something like this list
alpha123_4rf_Joe
45beta_Frank
Red5Great_Sam_Fun
and I would like to be left with (with a notepad++ regex find and replace)
alpha123_4rf
45beta
Red5Great_Sam
I am just looking for the Regex as I understand notepad++ :-)
Try this one:
_[^_]+$
Replace with an empty string.
To explain it:
_ match a single _ character
[^_]+ match any character that is not a _ character, one or more times (+)
$ match the end of the string
You can use:
/^(.*)(_.*?)$/\1/
Demo
If you are attempting to do this for PromQL label_replace to use for grouping as I was, this will be helpful to you:
[^.*]+_(.*?)$
I know this post is about notepad++ - however this post kept coming up in my searches and I found that the given solutions did not work with PromQLs variant of regex. Adding this answer for future folks landing here for similar reasons.

Regex replace keeping part of a string and adding data

I have this file with thousands of records (more thank 300.000) and I have to replace all the occurrences of a particular string but keeping some of it.
I'll give you an example, the string would be
\123
\34565
\923
..etc
so basically I would have to convert these strings in to
'|''|'123'
'|''|'34565'
'|''|'923'
does anyone have a quick solution for this?
Many thanks
Try this -
Regex - \\(\d+)
Replace with - '|''|'\1'
Demo here
Use this regex:
\\(\d+)
You should use g(global) modifier to match all. So your final regex would become:
/\\(\d+)/g
and replace it with:
'|''|'$1'
Demo:http://regex101.com/r/yO3xQ6

(Notepad++) Replace with regular expression: FixedText(xxx[yyy],whatever) to FixedText(yyy, xxx[yyy],whatever)

Sorry for not knowing the basics of regular expressions and asking this, but I couldn't get to it myself.
I need to replace all expressions PlayerTextDrawSetString(SSbank[playerid],strBank)
with PlayerTextDrawSetString(playerid,SSbank[playerid],strBank)
,
PlayerTextDrawSetString(SWant[someid],strWant)
with PlayerTextDrawSetString(someid,SWant[someid],strWant)
etc.
I can find such expressions with PlayerTextDrawSetString+\(+.+\[+.+\], but I can't replace them with that (\1, \2, \3 etc. return empty symbol).
I tried different search strings, but in all cases I get nothing on \1, \2, etc.
Could you please write the correct regex for me?
Thank you in advance for the help.
Try these expressions:
Search:
(PlayerTextDrawSetString\()(\w+\[)(\w+)
Replace:
\1\3,\2\3
The first two examples work.
Search Pattern 1:
SSbank\[([^\]]+)\]
Replacement Pattern 1:
\1,SSbank[\1]
Search Pattern 2:
SWant\[([^\]]+)\]
Replacement Pattern 2:
\1,SWant[\1]
To go all out if you have a lot of these similar patterns you can do this:
Total Replacement Search:
\((\w+)\[([^\]]+)\]
Total Replacement String (yes the first slash is needed... a bug maybe?):
\(\2,\1[\2]
Look behind is apparently broken.
I tried to give Notepad++ a shot with the positive look behind but the replacement fails even though the match happens. Here's the pattern:
(?<=\()(\w+)\[([^\]]+)\]
My attempted replacement (doesn't replace anything in Notepad++ v6.3.2):
\2,\1[\2]

Notepad++ Regular Expressions find&remove

Need some help in Notepad++
Example how it looks at the moment
http://www.test.com/doc/rat.rar">rat.rar
http://www.test.com/down/ung.rar">ung.rar
http://www.test.com/read/add.rar">add.rar
......
How I want it (just remove after ">....rar)
http://www.test.com/doc/rat.rar
http://www.test.com/down/ung.rar
http://www.test.com/read/add.rar
Its a list about 1000 lines. So help would be nice
Use the following expression:
">[^.]+\.rar
Explanation:
"> # literal `"` followed by literal `>`
[^.]+ # any character that is not a `.`, repeated at least once
\. # literal `.` character
rar # literal string `rar`
Note: a couple of other answers pointed out that just ">.* will work. This is true, because Notepad++ doesn't appear to support multi-line regular expressions, even with [\s\S]+. Either way will work so it's personal preference. The regex I gave in this answer is very verbose and would reduce the likelihood of false positives. ">.*, on the other hand, is shorter.
In regexp mode , replace pattern ">.* with empty string.
">.*
Search for this and replace with nothing.
Your search string should be ">.+\.rar, and you can just blank out the replace box. This should do the job.
Also, check that you've got regex selected at the bottom of the replace box ;)
If you put this in find ".* and nothing in replace, that should do what you're looking for.
Remember to check that you've got regex selected at the bottom of the replace box.
Flick the "regular expression" radio button and then use this for your FIND:
">[a-z]+\.[a-z]+
Then just put empty space for your REPLACE and replace all.
Use -
Find What : (.*)">(.*)
Replace With : \1
And check Regular expression option at the bottom of the dialog.