Notepad++ Wildcard Find/Replace - regex

I'm using Notepad++ and need to update a file where there are various differences in earlier sections of the string of text and think Wildcards may help here. From the research I've done thus far, it isn't clear what syntax would be used for this.
Here's an example of the original string:
"EEID","SUPLIFE","Voluntary Life Insurance","500000.00","500000.00",0,276,10.62.0,0,0,"20151112","","A","","","","",""
I'd like to find a way to add wildcards in the places noted below as WILDCARD:
"EEID","SUPLIFE","Voluntary Life Insurance","WILDCARD","WILDCARD",WILDCARD,WILDCARD,WILDCARD,WILDCARD,WILDCARD,WILDCARD,"20151112","","A","","","","",""
The final output would then look like the following after the find/replace with wildcards to add VLIFE:
"EEID","SUPLIFE","Voluntary Life Insurance","500000.00","500000.00",0,276,10.62.0,0,0,"20151112","","A","VLIFE","","","",""
Thanks,
Brandon

Tested in Notepad++ and appears to work:
("EEID","SUPLIFE","Voluntary Life Insurance",([^,]+,){8}"","A",)("")(.*)
and replace pattern:
\1"VLIFE"\4
Regex101 example

Related

Regex to match everything."LettersNumbers"."extension" and forum searching tip

I would need a regex to match my files named "something".Title"numberFrom1to99".mp4 on Windows' File Explorer, my first approach as a regex newbie was something like
"..mp4"
, but it didn't work, so i tried
"*.Title[1-9][0-9].mp4"
, that also did not work.
I would also like a tip on how to search regex related advices on Stackoverflow archive but also on the web, so that i can be specific, but without having the regex in the searching bar interact.
Thank you!
EDIT
About the second part of the question: in the question itself there is written "..mp4" but i wrote "asterisk"."asterisk".mp4, is there any universal way to write regex on the web without it having effect and without escaping the characters? (in that way the backslash shows inside the regex, and that could be misunderstood)
Try something like this:
(.*)\.[A-za-z]+\d+\.mp4
See this Regex Demo to get an explanation on the regex.
Use regex101.com to test your regexs
Here it is:
^[\s\S]*\.Title[1-9][0-9]?\.mp4$
I suggest regexr.com to find many interesting regexes(Favourites tab) and simple tutorial.
About the second part of the question: in the question itself there is written "..mp4" but i wrote "asterisk"."asterisk".mp4, is there any universal way to write regex on the web without it having effect and without escaping the characters? (in that way the backslash shows inside the regex, and that could be misunderstood)

Regex find text between two hash comments

I want to find and replace text between to hash comments. e.g I want to find if there is a text something like below within #string_start and #string_end
#string_start
this could be any text here
and here
#string_end
I tried this code but it didn't work and I know I am not using the corrent syntax due to my lack of regex knowledge.
\#string_start(.*?)\#string_end
#string_start\n([\s\S]*?)#string_end
Try this.Grab the capture.See demo.
https://regex101.com/r/vD5iH9/61

Replacing chemform in wiki - regexp

could you please give me some advice, I'm replacing the <chemform> code from my wiki which is not used any more... The strings are usually simple like these:
<chemform>CH3COO-</chemform>
<chemform>Ba2+</chemform>
<chemform>H2CO3</chemform>
I need them to be replaced by these:
CH<sub>3</sub>COO<sup>-</sup>
Ba<sub>2</sub><sup>+</sup>
H<sub>2</sub>CO<sub>3</sub>
So far I came up with this regexp for the RegExr tool:
match: <chemform\b[^>]*>(\D*?)([0-9]*)(\D*?)(\D*?)([0-9]*)(\D*?)([-+]*?)</chemform>
replace: $1<sub>$2</sub>$3$4<sub>$5</sub>$6<sup>$7</sup>
I know the code is horrible, but so far it's been working for me except for the fact it's getting me empty strings like <sub></sub>:
<sub></sub>CH<sub>3</sub>COO<sup>-</sup>
<sub></sub>Ba<sub>2</sub><sup>+</sup>
H<sub>2</sub>CO<sub>3</sub><sup></sup>
How can I get rid of these without doing second replace search? Thanks a lot!
You could use Notepad++, which is able to proceed to conditional replacements (you can have details in that previous post from Wiktor Stribiżew).
Use the following patterns:
match: ([A-Za-z]+(?=[-+\d]))(?<sub>\d+)?(?<sup>[-+])?(?=[-+\w]*</chemform>)
replace: $1(?{sub}<sub>$+{sub}</sub>)(?{sup}<sup>$+{sup}</sup>)
Given your input sample, I get:
<chemform>CH<sub>3</sub>COO<sup>-</sup></chemform>
<chemform>Ba<sub>2</sub><sup>+</sup></chemform>
<chemform>H<sub>2</sub>CO<sub>3</sub></chemform>

RegEx Search & Replace (via Dreamweaver CS5)

I have to deal with a problem and maybe you can help.
I took over a Website with a lot of code and would like to have it run on PHP 5.4.
But there are a LOT of statement's like this:
if($arrayname['keyname']>"") ....
I would like to replace them all with:
if(!empty($arrayname['keyname'])) ....
Doing it manually will take forever :-(
Do you know how to use Dreamweaver's CS5 search & replace with RegEx capabilites - unfortunately my RegEx knwoledge is limited.
Of course the regex must be "variable, as the arrayname and the keyname always changes.
Any help on finding the correct RegEx Stamtent is HIGHLY appreciated .
Regex to find all occurrences of if($arrayname['keyname']>""), whatever arrayname and keyname are, if only letters :
if\\(\\$[a-zA-Z]*\\[\'[a-zA-Z]*\'\\]>\"\"\\)
You'll have to find how to use BackReferences in Dreamweaver. If it uses standard Regex, then use the tutorial in the link, it will be of great help for you.
To complete and close this question:
In Dreamweaver search for (Regex Search in Code):
if\(\$(\w+)\[['"](\w+)['"]\]>""\)
Replace by:
if(!empty($$1['$2']))

Regex - match a string not contain a 'semi-word'

I tried to make regex syntax for that but I failed.
I have 2 variables
PlayerInfo[playerid][pLevel]
and
Character[playerid]
and I want to catch only the second variable,I mean only the world what don't contain PlayerInfo, but cointains [playerid]
"(\S+)\[playerid\]" cath both words and (\S+[^PlayerInfo])\[playerid\] jump on some variables- they contais p,l,a,y ...
I need to replace in notepad++,all variables like Text[playerid] to ExClass [playerid][Text]
Couple Pluasible solutions.
List item
Notepad has a plugin called python script. Running regex from there
gives full regex functionality, the python version anyway, and a lot
of powerful potential beyond that. And I use the online python regex tester to help out.
RegRexReplace plugin helps create regex plugins in Notepad++, so when you do hit a limitation, you find out a lot quicker.
Or of course default to your alternate editor (I'm assuming you have
one?) or this online regex tool is absolutely amazing. You
can perform the action on the text online as well.
(I'd try to build a regex for you, but I'm a bit lost as to what you're looking for. Unless the Ivo Abeloos got it. If you're still coming up short, maybe a code example along with values displayed?)
Good luck!
It seems that Notepad++ support negative lookbehind since v6.
In notepad++ you could try to replace (.+)\[(.+)\] with ExClass\[\2\]\[\1\]
Try to use negative lookbehind.
(?<!PlayerInfo)\[playerid\]
EDIT: unfortunately notepad++ does not support negative lookbehind.
I tried to make a workaround based on the following naive idea:
(.[^o]|[^f]o)[playerid]
But this expression does not work either. Notepad++ seems to fail in alternative operator. Thus the answer is: it is impossible to do exactly what you want. Try to solve the problem in other way or use alternative tool.