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

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)

Related

Regular expression Notepad++

Good Morning in my timezone
I want to replace a character that is in the beginning of each line
So i had used the following regular expression to find the text
^\d
And it works fine in finding all the characters
The problem is in the replace with
I want to replace with single quote followed by the same character found above
How can i do it ?
Thanks in advance
You may try this option:
Find:
^(?=\d)
Replace:
' <-- just a single quote
The find pattern uses a positive lookahead which asserts that the first character is a digit, but nothing is ever matched. Then, the replacement is a single quote.
You may use
Find What: ^\d
Replace With: '$0
where $0 is the backreference to the match value.
Another one would be:
Find:
^(\d)
Replace:
'\1
In this example \1 would be 1st captured group.

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:

Regular expression find/replace notepad++

I've a huge text file with lines like this:
080012;Bovalino;RC;CAL;0964;89034;B098;9021;http://www.website-most.en/000/000/
And i would like extract only:
080012;***Bovalino***;***RC***;CAL;***0964***;***89034***;B098;9021;http://www.website-most.en/000/000/
And delete all other text.
Can this be done with regular expressions?
You can capture the stuff you want to keep and use a backreference in the replacement string:
Find what: ^\d*;(\w*;\w*);\w*;(\d*;\d*).*
Replace with: \1;\2
And make sure you do not tick the . matches newline option.
With Notepad++ 6 you can also use $1;$2 for the replacement (with the same meaning).
If the different fields may contain all sorts of characters and not just digits and letters, this is probably your best bet:
Find what: ^[^;]*;([^;]*;[^;]*);[^;]*;([^;]*;[^;]*).*

notepad++ regex remove numbers

I have a notepad++ text file with:
have 9456
do 9823781
no 83270
tell 342
and it continues like that.
What is the regex for removing the space and numbers from the file?
You want to replace [0-9 ]+ with empty string with the regex option enabled.
Use the following as your search string:
\d+$
Remember to have the Search Mode set to Regular Expression.
Find space and digits easy as one two three
Search \s\d+
Replace all with: nothing