Notepad++ Search Multiple and Replace Respectively - string

Doing some String manipulation and I want to ask if the below is possible in Notepad++:
I have a string with Years:
10-Jan-13
22-Feb-14
10-Jan-13
10-Mar-13
I want
10-JAN-13
22-FEB-14
10-JAN-13
10-MAR-13
(There's more data on each line there but I am just showing a simplified example).
I know I can OR search with | character so find, JAN|FEB|MAR... but how do I replace according to what's found.
(Just trying to save some time)
Thanks.

Not sure if it's a plugin or built-in, but you can use the TextFX Characters plugin, to select the text, and then in the textfx characters dropdown, click UPPER CASE.
Update
Looks like it is a plugin:
TextFX menu is missing in Notepad++
Multiple Files
I found this site which gives a way to convert text to uppercase with regular expressions: http://vim.wikia.com/wiki/Changing_case_with_regular_expressions
So, what you can do is bring up the find in files dialog (CTRL+SHIFT+F), change search mode to Regular Expression, and then use something like this:
Find: (\d{2}-\w{3}-\d{2})
Replace with: \U\1
Directory: Whichever directory your files are in (and only the files you want changed).
\U is an uppercase flag, and the brackets in the Find regex correspond with the \1 backreference, which will basically replace it with itself (but uppercase).

Related

How to ignore accented letters when using the search function of Sublime Text?

When searching for text in Sublime Text, the search is sensitive to accented letters. This is not very practical when I want to find all matches regardless of the accents. Is there a setting for the search function that makes it ignore the accents?
Unfortunately Sublime Text's Find feature does not support Character Equivalence, so there is no way to get it to ignore the accents.
I explored this before in the context of snippets and replacements, but for this use case, you could write a Python plugin to build the character equivalence for you and populate the Find panel appropriately.
You may find it is enough to just temporarily replace the whole file with it's unidecoded representation and search that.

Is there a quick way to delete everything between certain tags, e.g. <head> and </head>, throughout the whole project (multiple pages) in VS Code?

I am trying to find a way to remove all from a tag pair in VS Code.
I’ve been using Notepad++ for this purpose, but for some unknown reason it doesn't work all the time. So, I hope if there is such a possibility in VS Code, it’d be more reliable.
Here is the instruction for Notepad++:
Search for -
<wp:post_name>[^<>]+</wp:post_name>
and replace all with -
<wp:post_name></wp:post_name>
Is there anything like this in VS Code?
I’d really appreciate it if someone can help.
Before using what is suggested in this solution, backup your files, and run the search and replace on a small sample. Be sure to check the outcome to all the possible combinations you can have in your files.
You can achieve what you need with Notepad++ (and SublimeText 3, with RegEx search and replace), and this answer will cover that. Since I've never used Visual Studio Code, I can't say if it will work in it as well.
Consider the following regular expression.
<foo>(.*?)<\/foo>
If we were to apply it to the following text:
<foo><some special chars>!##$%^&*</foo> sure, why not
<foo>Lorem</foo>
<foo>ipsum</foo>
<foo>sit</foo>
<foo>dolor</foo>
<foo>amet</foo>
<bar>elm stuff</bar>
more stuff for you <foo> something </foo> and even more stuff <foo>yes</foo>
it would match all the parts of the text which begin with <foo> and end with </foo>, regardless of what's between them.
If you want to play around with this, I've created an example here.
As far as using this in Notepad++, open the search window, navigate to the Find in files tab, and set it up like in the following image.
You would, of course, need to change the search and replacement strings to those you plan on using, optionally set up a file extension for which to do the replacement (Filters), and set the directory in which to perform find-and-replace.
Limitations
1. Nesting
In case your text contains nested tags of the same kind, like this:
Let's deal with nesting: <foo> some text <foo> a child foo!</foo> let's close the parent</foo>
doing the suggested RegEx search and replace, will turn the previous line of text into this:
Let's deal with nesting: <foo></foo> let's close the parent</foo>
If you don't have nested tags of the same kind, you should be in the clear. Unless...
2. Newlines
The provided RegEx will not match cases where your opening tag shows up in one line, and the closing tag shows up in another line. To match those, you would need to change the original RegEx:
<foo>(.*?)<\/foo>
to this:
<foo>([\s\S]*?)<\/foo>
\s will match any whitespace character (including newlines), while \S will match any non-whitespace character.

Adding comma and quotes for two columns in sublime on Mac

I have data in sublime arranged as follows;
353154 0.001039699782
506472 0.02085443362
482346 0.08343533852
439791 0.001349253676
486087 0.9999999476
I am trying to put quotes and commas so as to get following output;
('353154', '0.001039699782'),
('506472', '0.02085443362'),
('482346', '0.08343533852'),
('439791', '0.001349253676'),
('486087', '0.9999999476')
I am aware of using CMD+Shift+L in order to move cursors right and left. But I need help on how to get the commas and quotes between the two columns. Kindly advise.
You can do this with regex search and replace. Select Find → Replace… and make sure the Regular Expression button (usually looking like this *) is selected. In the Find: field, enter
([\d\.]+)\s+([\d\.]+)
and in the Replace: field, enter
('\1', '\2'),
Hit Replace All and it will look like this
See the demo at regex101.com, which also explains what each of the capture and replacement groups do.
Please keep in mind that you'll have to delete the final comma , if that's not proper syntax for your language of choice.

Is there any way to copy few characters to clipboard in textpad?

I'm trying to replace a few character word in one place with the word searched in another. I.e
VARIABLE INT005 SOME TEXT BETWEEN NAME=INT020;
I want the program To copy whats after VARIABLE (INT005 in this case) and paste it after NAME=(here should be again INT005 replaced into the place of INT020)
A regex replacement should work here. Assuming you are only looking to make these replacements on a single line, you may try the following find and replace:
Find: \bVARIABLE (\S+)(.*?)\bNAME=\S+;
Replace: VARIABLE $1$2NAME=$1
Demo
Edit:
If your text could span multiple lines, then either turn on "dot all" mode from Textpad (not sure where you would do that), or use this find version:
\bVARIABLE (\S+)([\s\S]*?)\bNAME=\S+;

How to delete text in a file based on regular expression using vim

I have an XML file like this:
<fruit><apple>100</apple><banana>200</banana></fruit>
<fruit><apple>150</apple><banana>250</banana></fruit>
Now I want delete all the text in the file except the words in tag apple. That is, the file should contain:
100
150
How can I achive this?
:%s/.*apple>\(.*\)<\/apple.*/\1/
That should do what you need. Worked for me.
Basically just grabbing everything up to and including the tag, then backreferences everything between the apple begin and end tag, and matches to the rest of the line. Replaces it with the first backreference, which was the stuff between the apple tags.
I personally use this:
%s;.*<apple>\(\d*\)</apple>.*;\1;
Since the text contain '/' which is the default seperator,and by using ';' as sep makes the code clearer.
And I found that non-greedy match #Conspicuous Compiler mentioned should be
\{-}
instead of "{-}" in Vim.
However, I after change Conspicuous' solution to
%s/.*apple>(.\{-\})<\/apple.*/\1^M/g
my Vim said it can't find the pattern.
In this case, one can use the general technique for collecting pattern matches
explained in my answer to the question "How to extract regex matches
using Vim".
In order to collect and store all of the matches in a list, run the Ex command
:let t=[] | %s/<apple>\(.\{-}\)<\/apple>\zs/\=add(t,submatch(1))[1:0]/g
The command purposely does not change the buffer's contents, only collects the
matched text. To set the contents of the current buffer to the
newline-separated list of matches, use the command
:0pu=t | +,$d_

Resources