Trying to replace some text in Notepad++ - regex

Using notepad++ to find and replace some variables but also add some items.
I need
<date>20140427</date>
replaced with
<previously-shown start="2014-04-27"></previously-shown>
So far I have
Find what:
<date>\d{4}\d{2}\d{2}</date>
replace with:
{<previously-shown start="} + \3-\2-\1"></previously-shown>

Add capturing groups to the pattern and change the order of the backreferences in the replacement:
Find What: <date>(\d{4})(\d{2})(\d{2})</date>
Replace With: <previously-shown start="$1-$2-$3"></previously-shown>
See the regex demo.

Related

How in notepad++ find/replace text between slashes?

How to find the text between the second and fourth slashes in a path like /folder/subfolder-1/subfolder-2/subfolder-3? I’m trying to replace this with something like /folder/new-folder/subfolder-3.
The most important for me is to be able to find the part after the n-th slash.
I tried the regex /((.*?)/){3}, but it doesn’t work.
Using Match resetter \K meta-character you are able to do it in a simpler way.
Find:
/.*?/\K(.*?/){2}
Replace with:
new-folder/
One way you could to it is by using this string in the pattern to replace
(/.+?)(/.+?){2}(/\S+)
And use this one in your pattern to replace it with
$1/new-folder$3
From your string:
/folder/subfolder-1/subfolder-2/subfolder-3
(/.+?) will match /folder as $1
(/.+?){2} will match /subfolder-1/subfolder-2 as $2 (not used)
(/\S+) will match everything that isn't a space, in this case/subfolder-3 as $3
Leaving you room to insert your new-folder in-between.
How can I just mark till the slash?
Find what: (/[^/]+/)[^/]+/[^/]+
Replace with: $1new-folder
To find text between second and forth slash you can use the regex ^(/[^/]*/)([^/]*/[^/]*) then you can reference to the text between slashes with \2 when replacing the text.
To keep the text before the slashes you can enter something like \1myNewTextBetweenSlashes2and4.
In notepad++ Find by this:
(/[^/]+)(?:/[^/]+/[^/]+/)(.*)
And Replace by this:
\1\/new-folder/\2
Make sure that: .matches newline is not checked
{2} indicates 2 levels after first level will be repalced by new-folder
Find:
(\/.*?\/)(.*?\/){2}(.*)
Replace:
$1new-folder/$3
Demo: https://regex101.com/r/XIA3IN/3

Notepad++ - RegEx - Number and Date

I have the following text in NotePad++, I am trying to write a RegEx to find and replace with the following.
Find: #,##/ (Look for the pattern 2,10/)
Replace: #\r (at the comma replace with a new line, so the date starts on a new line)
11/02/2016,18,54,61,13,37,05,2,10/29/2016,42,48,20,21,19,23,3,10/26/2016,48,56,02,16,03,24,2,10/22/2016,01,55,33,28,56,22,2,10/19/2016,43,63,16,38,10,23,2,10/15/2016,64,49,57,23,67,20,2,10/12/2016,34,44,30,16,37,16,2,
You seem to be looking for capturing groups: capture the different parts that should get split with a newline and use backreferences in the replacement pattern.
Search: (\d,)(\d+/)
Replace: $1\n$2
See the NPP screenshot:
This regex will work: (\d),(\d\d/)
Replace with: \1\r\2
Result example:

How to replace the single quotes on Word/notepad++

I would like to replace the single quotes from the number in the below text.
('28','Harry Potter');
The output required is
(28,'Harry Potter');
What kind of regex is required to remove the quotes in Word/notepad++ ?
How about:
Ctrl+H
Find what: '(\d+)'
Replace with: $1
Then click on Replace all
This will remove all single quotes arround digits.
For Word 2010:
Use
Find what:
([0-9]{2,})
replace with:
\1

How to cut string with Regex and Notepad++

I need to use Notepad++ to cut the string in the text file using regex.
I have this type of strings: "<a href="/groups/1122some_text_here/sometexthere"AnotherText
I need to replace it with: "<a href="/groups/1122/"AnotherText
I need to keep only numbers and close it with slash.
I could get all entries with /groups/[\d].* regex.
How to replace it in a right way?
You can use the following replacement:
Find What: (?<=/groups/)(\d+).*?"
Replacement: $1/>
Or, perhaps, adding the closing angle bracket:
Find: (?<=/groups/)(\d+).*?"
Replace: $1/">

Notepad++ Regex - Find multiple characters and replace them with one character

I have a file with +20K lines and some strings have this structure:
,"/d/s/aaa.jpg","/e/_/bbb.jpg","/_/2/bbb.jpg" ....
and I want to replace them with:
,"/aaa.jpg", "/bbb.jpg","/bbb.jpg" ...
Can some one provide me a regex expression that will find those 5 leading characters and replace them with "/"?
Thank You in advance.
Use the following:
Find what: /[^/]+/[^/]+(/[^/]+\.jpg)
Replace with: $1
Edited:
The following:
\"\/[^/]+\/[^/]+\/
will match the "/d/s/ or "/e/_/ part of a string. You can test it here: http://regexpal.com/
Make sure to replace it with:
"/
to do more you would need capture groups (i.e. capturing some parts of the regex to reuse that in the substitution or manipulate it somehow)