Regex find text between two hash comments - regex

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

Related

Notepad++ Wildcard Find/Replace

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

Issues with RegEx

I am trying to make an if-then-else statement using RegEx. I want to match the text if it contains Monty and also contains Python. Also the text should get matched if Monty is not present in the text.
RegEx
(?(?=Monty)(?(?=Python).*|)|^.*).*$
Kindly help!
How about this:
(^(?!.*Monty(?!.*Python.*).*).*$|^.*Python.*Monty.*$)
This passes my tests, but let me know if it works for you.
I am not versed in lookahead regex but just tried to build the regex from what I understood from above description. Check the link to see if this is what you are trying to do.
try this instead
((?=Monty)((?=Python).*|)|^.*).*$

Filtering specific word form sentence by regex

I am trying to make a regular expression which will give an error when user will give specific input like feat, ft. I do want to allow this kind of input in a sentence. How can I solved this problem.
For example:
The feat-incorrect
featable-corroct
rahin (feat)-incorrect
feat-incorrect
I create one
regex: /^(?!.(feat|artists|Diverse artister|Feat|Feat.Featuring)).$/
in this regex
featable- is incorrect. But I need this one correct
has Anyone solved this kind of problem? Thanks in advance.
If your question is how to create a REGEX that selects whole words and not part of a word then try something like this:
\bfeat\b
If you want the only correct word to be featable then use \bfeatable\b
check out this Regex Expression builder, its useful. the builder would highlight the correct words for the expression you put.

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>

Searching my code with regex

It happens all the time, I would need to scan my code for places where I have two or more of the same keywords.
For example $json["VALID"]
So, I would need to find json, and VALID.
Some places in the code may contain:
// a = $json['VALID']; // (note the apostrophes)
(I am using EditPlus which is a great text editor, letting me use regex in my searches)
What would be the string in the regex to find json and VALID (in this example) ?
Thanks in advance!
Use this regex:
\$json\[["']VALID['"]\]
wound find $json<2 character>VALID
\$json.{2}VALID