GREP changing function when applying 'change all' - replace

OK, so this is really weird. I'm running this GREP to add space between closing quote marks/apostrophes and footnotes.
Find:
(~])(~F)
Change:
~]~|$2
This works great when I change them one by one, but when I hit the 'change all' button it just deletes all the found footnotes! I have hundreds of footnotes to change so any help would be much appreciated as I don't really want to change them one at a time when this should be unnecessary.

The idea is to not touch the footnote marker while still looking for it. A search using a lookahead: ~](?=~F) and changing it to ~]~| should work

Related

select area within characters using regex (spaces are an issue)

Some other guy asked a similar question earlier which got a lot of down votes, and I was interested in solving it. I came to a similar issue and would like some help with it.
Take into consideration this wall of text:
__don't__ and __do it__
__yellow__
__green__ and __purple__
I would like to select all the area within the underscores __'s
I attempted the following regex:
/__[!-~]+__/g which worked great on most things. I would like to add the ability to have spaces within the underscores. __do it__ will not be encapsulated in the search because it includes a space which was ruled out by the regex. I attempted the following:
/__[ -~]+__/g
It didn't work as planned, and selected everything from the very first __ to the very last. I was wondering how to tell the regex it has reached the end of a search once it sees a space after a __.
Here is the regex you could play around with below:
http://regexr.com/39br7
I tried using __[^ ]/g at the end but It didn't seem to help.
You could simply use the below regex,
__[^_]*__
DEMO
__(.*?)__
This seems to work.Look at the demo.
http://regex101.com/r/lJ1jB1/1

I have a file with so many lines which needs find and replace in shell

I have lines like
SC2268,Registration lauch causes a menu of what the user wants to do
I need to change this to
[SC2268]:Registration lauch causes a menu of what the user wants to do
I have tried the following things:
1.%s/\(\w\+\),\(\w\+\)/\[1]:\2/gi
2.%s/\(SC[0-9]*\)/\[1]/gi
But no luck.
:%s/^\([^,]*\),/[\1]:/
looks reasonable to me (EDIT: Thanks #Sven for pointing out I needed to change the , into :)
You're close. The symbol to insert the first match is \1; the backslash must be directly before the number:
:%s/\(SC[0-9]*\)/[\1]/gi
The escaping and syntax of the {pattern} and {replacement} parts in :s/{pattern}/{replacement}/ are different! When in doubt, please consult the help:
:help pattern
:help s/\1
Also note that there are shorter ways for this particular one; see (and try to understand) #bobbogo's answer.

How do I join two regular expressions into one in Notepad++?

I've been searching a lot in the web and in here but I can't find a solution to this.
I have to make two replacements in all registry paths saved in a text file as follows:
replace all asterisc with: [#42]
replace all single backslashes with two.
I already have two expressions that do this right:
1st case:
Find: (\*) - Replace: \[#42\]
2nd case:
Find: ([^\\])(\\)([^\\]) - Replace: $1$2\\$3
Now, all I want is to join them together into just one expression so that I can do run this in one time only.
I'm using Notepad++ 6.5.1 in Windows 7 (64 bits).
Example line in which I want this to work (I include backslashes but i don't know if they will appear right in the html):
HKLM\SOFTWARE\Classes\*\shellex\ContextMenuHandlers\
I already tried separating it with a pipe, like I do in Jscript (WSH), but it doesn't work here. I also tried a lot of other things but none worked.
Any help?
Thanks!
Edit: I have put all the backslashes right, but the page html seem to be "eating" some of them!
Edit2: Someone reedited my text to include an accent that doesn't remove the backslashes, so the expressions went wrong again. But I got it and fixed it. ;-)
Sorry, but this was my first post here. :)
As everyone else already mentioned this is not possible.
But, you can achieve what you want in Notepad++ by using a Macro.
Go to "Macro" > "Start Recording" menu, apply those two search and replace regular expressions, press "Stop Recording", then "Save Current Recorded Macro", there give it a name, assign a shortcut, and you are done. You now can reuse the same replacements whenever you want with one shortcut.
Since your replacement strings are totally different and use data that come not from any capture (i.e. [#42]), you can't.
Keep in mind that replacement strings are only masks, and can not contain any conditional content.

REGEX: best practice to insert before, after or between?

i'm nervous as hell asking this question since there's a LOT of RegEx posts out there. but i'm asking for best method as well, so i'm going to risk it (fully expecting a rep hit if i botch the job...)
i've been given a list to reformat. 120 questions and answers (240 tag sets total). * glark * all i need to do is make the text between the tags a link, like so:
<li>do snails make your feet itch?</li>
has to become
<li>do snails make your feet itch?</li>`
THIS IS NOT A JAVASCRIPT/PHP RegEx question. it is JUST RegEx that i can drop into the search/replace fields of my IDE. i'll likely try and do a batch replace afterwards with PERL to insert the 'n' variable so the links point properly.
and i know you're going to ask 'if you can use PERL for that, why not the whole shebang?' and that's a valid question, but i want to be using RegEx more for the power it has for big lists like this. plus my PERL skills are sketchy at best... unless you want to tack that on as well... :D heh heh.
if this question can't be answered or is wrong for this part of the forum, please accept my apologies and point me in the right direction.
many thanks!
WR!
You can do it in two steps.
Substitute <li> with <li><a href="#n">
Substitute </li> with </a></li>
Or you can try to be clever and it it in one. Here is a substitute command in Perl syntax ($1 references what was matched in the brackets).
s,<li>(.*)</li>,<li>$1</li>,
And while you are there it's easy to replace the second part of the replacement pattern with an expression that will increment n
s,<li>(.*)</li>,q{<li>$1</li>},e
See how you can run this from the command line:
echo '<li>do snails make your feet itch?</li>' |
perl -pe 's,<li>(.*)</li>,q{<li>$1</li>},e'
<li>do snails make your feet itch?</li>
Search
<li>(.*?)</li>
Replace
<li>$1</li>

Create a valid CSV with regular expressions

I have a horribly formated, tab delimited, "CSV" that I'm trying to clean up.
I would like to quote all the fields; currently only some of them are. I'm trying to go through, tab by tab, and add quotes if necessary.
This RegEx will give me all the tabs.
\t
This RegEx will give me the tabs that do not END with a ".
\t(?!")
How do I get the tabs that do not start with a "?
Generally for these kinds of problems, if it's a one time occurrence, I will use Excels capabilities or other applications (SSIS? T-SQL?) to produce the desired output.
A general purpose regex will usually run into bizarre exceptions and getting it just right will often take longer and is prone to missed groups your regex didn't catch.
If this is going to happen regularly, try to fix the problem at the source and/or create a special utility program to do it.
Use negative lookbehind: (?<!")\t
For one shots like this I usually just write a little program to clean up the data, that way I also can add some validation to make sure it really has converted properly after the run. I have nothing against regex but often in my case it takes longer for me figure out the regex expression than writing a small program. :)
edit: come to think about it, the main motivator is that it is more fun - for me at least :)