I ran a dir /s command to list files in folders & sub-folders, and to show the file size. My issue is that I use a "," as a separator between the file name and size.
Is their any way to find the last comma in the and replace it with";"?
My text file looks like this:
H:\IP Phones, Mobile Information.xls,152064
H:\Master Sheet Updated.xlsx,46446
The following regex will match a comma that is not followed by .* (any number of any character) and a comma.
,(?!.*?,)
Then just use the Replace... functionality in Sublime (Ctrl+H) and it should work.
Related
I am looking to create a regex for searching Notepad++
I have a notepad page with thousands of random codes such as:
415615610230
151156125611
161651651516
511111115165
I need to search the entire notepad for multiple codes with once search
I know the regex would look like (415615610230|151156125611|161651651516)
but what I need to do is build a regex like above by pasting in all my search criteria.
If I have say 100,000 numbers I might need to search the 100,000 numbers for 20 codes/numbers.
lets just say I want to search for
5155584865
5155584866
5155584867
5155584868
5155584869
5155584870
5155584871
5155584872
5155584873
5155584874
5155584875
5155584876
5155584877
5155584878
5155584879
5155584880
5155584881
5155584882
5155584883
5155584884
The regex should look like:
(5155584865|5155584866|5155584867|5155584868|5155584869|5155584870|5155584871|5155584872|5155584873|5155584874|5155584875|5155584876|5155584877|5155584878|5155584879|5155584880|5155584881|5155584882|5155584883|5155584884)
Is there a way to build the regex above by just pasting in
5155584865
5155584866
5155584867
5155584868
5155584869
5155584870
5155584871
5155584872
5155584873
5155584874
5155584875
5155584876
5155584877
5155584878
5155584879
5155584880
5155584881
5155584882
5155584883
5155584884
Or can anyone recommend an easier way to search the entire notepad document?
If you just want to search for the template above (e.g. starting with 51555848) the you can do
/51555848.([^\s]+)/g
This will match everything starting with 51555848 and ending with a whitespace.
copy your space separated numbers in a new document in your notepad++ and then replace all spaces or whitespaces (\s) with the pipe symbol (| or \| if your search mode is regex).
And you do not need the round brackets for your search string
EDIT:
Instructions for converting a list of numbers (line separated) into a regex
mark everything (ctrl + a)
join rows (ctrl + j)
replace (ctrl + h) with
search pattern: \s+
replace pattern: \|
search mode: Regex
I searched a lot but couldn't find any exact soluion.
I have a CSV which contains some values that contains a comma in between the values.
Following is a sample row
"BEIAAGJIPAMBPJIF",2757,08042010,"13:53.59",09042010,"01:55.39","SIHAM","BEIAIGHEIPLGPJIF",20,"A",20,"S",0.00,0.00,0.00,"OLY
SPECIAL ORDER","IN STOCK , DESIGNER",0.00000,0,"","N","N",
Now it you look at the value "IN STOCK , DESIGNER", it containts a comma in between. due to which while reading the csv in my .net application and in MS Dynamics CRM import file wizard, it breaks it into two seprate values instead of one single value.
I need a regex that can match such strings and replace the comma with a hyphen "-" that I can use in Notepad ++.
Kindly help.
Thanks.
This solution worked for me, although it is a bit indirect:
by searching, detect character which is unused in the file, e.g. #
use the following regex replace to replace all delimiters: find: (".*?"|.*?), replace: \1# (note the character from step 1)
now, all leftover commas are only those which are inside the quotes. Mass replace them for -
replace back all #'s for commas
I am trying to name a folder based on a file name, using regex in powershell.
The name looks something like this tester2-2013-14-10.txt.
With that file name being said, I want to create a folder named tester2. It will do this for all files in a directory. Basically the regex needs to read up until the first '-', then ignore all other characters after that. It
All regular expressions that I am trying have not worked to do such a things.
Here is the regex I am trying to use (\w+)\.txt.
And here it is when I try and implement it:
Get-ChildItem | Where{$_.Name -match '(\w+)\.txt'} | ForEach-Object{
md $matches[1]}
Along with other variations of this type of thing.
It appears that when I run a file name against this regex, it is using the end of the string. Such as in the case of tester2-2013-14-10.txt. The folder name that is being created is called 10 instead of Tester2.
Appreciate the help!
Try following regex
^(\w+)-.*\.txt
Refer to regex101 demo for validation and explanation.
Short Description
^ matches start of the line or string. It will ensure that match should be at the starting of a line.
Hence ^(\w+) will match the first word in the file name. Then it has to be followed by - and any characters until .txt
What's wrong with your regex?
(\w+)\.txt will match a word (\w+) immediately followed by .txt.
Hence you are getting last word instead of the first word.
I would like to extract paths in the form of:
$/Server/First Level Folder/Second_Level_Folder/My File.extension
The challenge here is that the paths are embedded in a "free form" email like so:
Hello,
You can download the file here:
$/Server/First Level Folder/Second_Level_Folder/My File.extension <- Click me!
Given a string, I would like to extract all paths from it using RegEx. Is this even possible?
Thanks!
Yes, this is possible (\$/.*?\.\S*) should do the job just fine.
\$/ matches the start of the path
.*? matches everything till the next part of the regex
\.\S* matches the dot and anything but a whitespace (space, tab)
And the ( ) around it make it capture all that is matched.
EDIT:
For further use
Just the path
(\$/.*?/)[^/]*?\.\S*
Just the filename
\$/.*?/([^/]*?\.\S*)
If the filename contains [escaped forward slashes / or no period symbol] AND the filepath spaces are escaped with a backslash '\ ' you can still do it with this (i've escaped the forward and back slashes)
(\/.*?\/)((?:[^\/]|\\\/)+?)(?:(?<!\\)\s|$)
Debuggex Demo
This creates two capture groups - one for the path and one for the file basename. If your test strings contains filenames with unescaped spaces (as shown) then you would have to use the period in the filename as an anchor as per B8vrede's answer.
I find Notepad++ regex to be very different from regex in Microsoft Word. I was wondering how I can group several lines of text using Notepad++. I have a text file with 100+ URLs. They are written one URL address per line. I would like to group all of them by tens by removing the carriage returns from every first to 9th line, but retaining the carriage return on every 10th line and adding another carriage return thereafter. For example:
I want this:
http://website1.com
http://website2.com
http://website3.com
http://website4.com
http://website5.com
http://website6.com
http://website7.com
http://website8.com
http://website9.com
http://website10.com
http://website11.com
http://website12.com
http://website13.com
http://website14.com
http://website15.com
http://website16.com
http://website17.com
http://website18.com
http://website19.com
http://website20.com
http://website21.com
http://website22.com
http://website23.com
http://website24.com
http://website25.com
http://website26.com
http://website27.com
http://website28.com
http://website29.com
http://website30.com
to look like:
http://website1.comhttp://website2.comhttp://website3.comhttp://website4.comhttp://website5.comhttp://website6.comhttp://website7.comhttp://website8.comhttp://website9.comhttp://website10.com
http://website11.comhttp://website12.comhttp://website13.comhttp://website14.comhttp://website15.comhttp://website16.comhttp://website17.comhttp://website18.comhttp://website19.comhttp://website20.com
http://website21.comhttp://website22.comhttp://website23.comhttp://website24.comhttp://website25.comhttp://website26.comhttp://website27.comhttp://website28.comhttp://website29.comhttp://website30.com
Any help would be appreciated!
Ok, I have found a way:
There is a such possibility, but only with 6 entries in a row (longest regex is not parsed by the Notepad++).
1)So, open the file and remove from it all newlines characters, so the text will be a long-long line.
2)Open replace dialog, insert in the "Find what" field the next :
(http://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.com)
and in the "Replace With" the next:
\1\r\n
Put the cursor at the first position in the text and press "Replace all"
So, the regex contains this (http://[^\:]*\.com){6} (the regex is repeated 6 times). If you work with Unix and you need unix-type new line style, replace this : \1\r\n with this \1\n