Regex Replace Whitespaces between single quotes - regex

I'm trying to find and replace a string into the wanted string, but can't get it to work.
For example:
1777: '23.5R25 Bridgestone VLT **',
Should be:
1777: '23.5R25-Bridgestone-VLT-**',
I'm having like 1,700 lines like this and want every whitespace between the single quotes to dashes. I'm using Notepad++ for this.
My approach:
Find: '(.*?)\s+(.*?)'
Replace: '\1-\2'
But this works for just 2 words.

\s(?!(?:[^']*'[^']*')*[^']*$)
You can use this and replace by -.See demo.
https://regex101.com/r/vP2zF2/2

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:

Remove multiple commas at the end of lines using Notepad++ regex replace

I have a text below with data in a CSV file
2,3
4,5
6,7
When I save an open this in notepad++, it has extra commas like
2,3,,,,
4,5,,
6,7,,,,,
like you see, there are variable number of leading commas,
I tried a regex match using:
/,{2,}/
I have selected the regular expressions combo-box from the search mode in ctrl + H Replace box.
For some reason this is not working. What do I need to do to match multiple comma and not get rid of single comma?
Is there a better way to get this done in notepad++?
Regex:
,{2,}$
Replacement string:
empty string
This will replace two or more trailing commas with an empty string. To remove all the trailing commas then use ,+$ regex.
\d+(?:,\d+)?\K.*$
You can use this.Replace by empty string.This will work with data like 2,3,
See demo.
https://regex101.com/r/iS6jF6/9

How to find and replace any characters between 2nd comma and 4th comma in a string using regex

I have a csv file which contains many lines of string like this:
001,bbb,002,ddd,eee,fff
I'd like to change it to:
001,bbb,eee,fff
using find/replace and regex
what is the right regex for this?
Find what:
^([^,]*,[^,]*),[^,]*,[^,]*,
OR
^([^,]*,[^,]*),\d+,[^,]*,
Replace with:
\1,
DEMO

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)