Batch rename files in Adobe Bridge - regex
I want to Batch Rename a few thousand files. I have one part of the regular expression figured out just not the first part.
The filename is the employeeID_employeeName-sequence number. I would like to only keep the employeeID_employee name.
For example the file 123456_John Smith-00001.pdf should become 123456_John Smith.pdf
I was able to use Batch Rename, then string substitution then, find [-\d?] but that only changes the filename to _John Smith.pdf
Please see batch rename example image
The expression that worked was by Wiktor Stribiżew in the comment above. In the string substitution field I placed -\d+(.\w+)$ and left the replace with field empty.
Related
Regex Assistance for replacing filepaths in markdown documents
I migrated my notes from evernote to markdown files with yarle. unfortunately it created me a lot of folders seperatively for the attachments (although I set it up for one folder only). I moved all attachements to one folder, so the filepath to the attachments in the mardown files needs to be updated. I think regex would be right for this, but I don't have any knowledge about regex and would be really thankful for help. Filepaths are as follows:![[./_attachmentsMove/Coordination_Patterns.resources/CoordinationPattern_Ipsi.MOV]] All filepaths are identical ![[./_attachmentsMove/]] up to this The second folder varies e.g. Coordination_Patterns.resources/. I want to delete everything but the filename.extension itself e.g. ![[CoordinationPattern_Ipsi.MOV]]. An example of the other filepaths: ![[./_attachmentsMove/Jonglieren_(Hände).resources/07 Jonglieren.MOV]] (second folder changes, filename changes, I also have .png and .mov). I use MassReplaceIt (app for mac) which allows me to replace expressions in documents with regex. If someone has a solution using the terminal/commandline, I'll try this as well of course :)
Try if this regexp suffices: (?<=!\[\[)[^\]]+/(?=[^\]/]+]]) Replace with empty string. It should delete the part from the ![[ up to the last / before the next ]].
Regex to extract all strings from source code used when calling a function
We have an old, grown project with thousands of php files and need to clean it up. Throughout the whole project we do have a lot of function calls similar to: trans('somestring1'); trans("SomeString2"); trans('more_string',$somevar); trans("anotherstring4",$somevar); trans($tx_key); trans($anotherKey,$somevar); All of those are embedded into the code and represent translation keys. I would like to find a way to extract all "translation keys" in all occurrences. The PHP project is in VS Code, so a RegEx Search would be helpful to list the results. Or I could search through the project with any other tool you would recommend However I would also need to "export" just the strings to a textfile or similar. The ideal result would be: somestring1 SomeString2 more_string anotherstring4 $tx_key $anotherKey As a bonus - if someone knows, how I could get the above list including filename where the result has been found - that would be really fantastic! Any help would be greatly appreciated! Update: The RegEx I came up with: /(trans)+\([^\)]*\)(\.[^\)]*\))?/gim list the full occurrence - How can I just get the first part of the result (between Single Quotes OR between Double Quotes OR beginning with $) See here: regexr.com/548d4
Here are some steps to get exactly what you want. Using this you can do a find and replace on your search results! So you could do sequential regex find/replaces in the right circumstances. The replace can be just within the search results editor and not affect the underlying files at all - which is what you want. You can also have the replace action actually edit the underlying files if you wish. [Hint: This technique can also make doing a find item a / replace with b in files that contain term c much easier to do.] (1) Open a new search editor: Ctrl+Shift+P (That command is currently unbound to a keybinding.) (2) Paste this regex into the Search input box (with the regex option .* selected): `(.*?)(\btrans\(['"]?)([^,'")]+)(.*)` - a relatively simple regex regex101 demo See my other answer for a regex to work with up to 6 entries per line: (\s*\d+:\s)?((.*?)(\btrans\(['"]?)([^,'")]*)((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?)(.*) (3) You will get a list of files with the search results. Now open a Find widget Shift+F in this Search editor. (4) Put the same regex into that Find input. Regex option selected. Put $3 into the Replace field. This only replaces in this Search editor - not the original files (although that can be done if you want it in some case). Replace All. If using the 1-6 version regex, replace with: $1$5 $9 $13 $17 $21 $25 (5) Voila. You can now save this Search Editor as a file.
The first answer works for one desired capture per line as in the original question. But that relatively simple regex won't work if there are two or more per line. The regex below works for up to 6 entries per line, like trans('somestring1'); stuff trans("SomeString2"); some content trans("SomeString2a");more stuff [repeat, repeat] But it doesn't for 7+ - you'll need a regex guru for that. Here is the process again with a twist of using a snippet in the Search Editor instead of a Find/Replace. Using a snippet allows more control over the formatting of the final result. (1) Open a new search editor: Ctrl+Shift+P (That command is currently unbound to a keybinding.) (2) Paste this regex into the Search input box (with the regex option .* selected): `((.*?)(\btrans\(['"]?)([^,'")]*)((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?((.*?)(\btrans\(['"]?)([^,'")]*))?)(.*)` regex101 demo (3) You will get a list of files with the search results. Now select all your results individually with Ctrl+Shift+L. (4) Trigger this keybinding: { "key": "alt+i", // whatever keybinding you like "command": "editor.action.insertSnippet", "when": "editorTextFocus", "args": { "snippet": "${TM_SELECTED_TEXT/((.*?)(\\btrans\\([\\'\\\"]?)([^,\\'\\\")]*)((.*?)(\\btrans\\([\\'\\\"]?)([^,\\'\\\")]*))?((.*?)(\\btrans\\([\\'\\\"]?)([^,\\'\\\")]*))?((.*?)(\\btrans\\([\\'\\\"]?)([^,\\'\\\")]*))?((.*?)(\\btrans\\([\\'\\\"]?)([^,\\'\\\")]*))?((.*?)(\\btrans\\([\\'\\\"]?)([^,\\'\\\")]*))?)(.*)/$4${8:+\n }$8${12:+\n }$12${16:+\n }$16${20:+\n }$20${24:+\n }$24/g}" } }, That snippet will be applied to each selection in your search result. This part ${8:+\n } is a conditional which adds a newline and some spaces if there is a capture group 8 - which would be a second trans(...) on a line. Demo: (unfortunately, it doesn't properly show the Ctrl+Shift+L selecting all lines individually or the Alt+i snippet trigger)
Search/replace in block selection in Notepad++
Is there a way to limit search/replace only to a columnar block selection in Notepad++? Here is what I am trying to do: I am bulk-editing metadata extracted from large numbers of photos. The metadata comes to me as a csv file with no quotes around fields in header line and no quotes around first field in each succeeding line. I edit this file in Open Office calc which exports with quotes around all fields. I can easily edit header row but the problem comes in stripping quotes from only first field in successive lines. I can use notepad in columnar mode but, after selecting the first column, the 'search only in selection' option box is greyed out. I can do this by hand but it means lots of hand-work and increased chance of error.
I know, this probably won't help you any more, but I just had the same problem and stumbled across this question. I found moving the block in question to a new file and performing the find/replace there works quite decently. When moving the block back, be sure to select it in block mode (see this question).
No. Another editor may have this feature.
sort of a late reply but... I had the same problem when I moved to a new machine with Notepad++ installed. Previously, I was using a text editor called Boxer that had this feature, which I found invaluable. Its not free-ware however.
You may not be able to Search/Replace within a columnar selection, but you can easily carry out your task within Notepad++. Use Find and Replace feature, with the Regular Expressions box checked. If you want to remove quotes only from a target column, use the following regular expression in the Find field: (^([^,]*,){i})"([^,\n\r]*)"(.*$) Replace i with the position of the target column minus 1. (i.e.- Us 2 if you want quotes around the third column, 0 for the first column, etc) In the Replace field use: \1\3\4 Clicking "Replace All" will strip quotes from the target column. If you want to blow away all quotes surrounding each element in your csv without prejudice, use the following regular expression in the Find field: ((?<=,)|(?<=^))"(.*?)"((?=$|,)) In the Replace field use: \1\2\3 Clicking Replace All will strip quotes form the columns. Example Since you didn't provide an example csv file, I'll walk through my own working example. Below is my csv: "0","1","2","3","4","5","6","7","8","9" "10","11","12","13","14","15","16","17","18","19" "20","21","22","23","24","25","26","27","28","29" "30","31","32","33","34","35","36","37","38","39" "40","41","42","43","44","45","46","47","48","49" "50","51","52","53","54","55","56","57","58","59" "60","61","62","63","64","65","66","67","68","69" "70","71","72","73","74","75","76","77","78","79" "80","81","82","83","84","85","86","87","88","89" "90","91","92","93","94","95","96","97","98","99" "100","101","102","103","104","105","106","107","108","109" "110","111","112","113","114","115","116","117","118","119" "120","121","122","123","124","125","126","127","128","129" "130","131","132","133","134","135","136","137","138","139" "140","141","142","143","144","145","146","147","148","149" "150","151","152","153","154","155","156","157","158","159" "160","161","162","163","164","165","166","167","168","169" "170","171","172","173","174","175","176","177","178","179" "180","181","182","183","184","185","186","187","188","189" "190","191","192","193","194","195","196","197","198","199" If I wanted to remove quotes from the second column, I would use the below Find and Replace fields (^([^,]*,){1})"([^,\n\r]*)"(.*$) \1"\3"\4 Clicking Replace All yields the below result: "0",1,"2","3","4","5","6","7","8","9" "10",11,"12","13","14","15","16","17","18","19" "20",21,"22","23","24","25","26","27","28","29" "30",31,"32","33","34","35","36","37","38","39" "40",41,"42","43","44","45","46","47","48","49" "50",51,"52","53","54","55","56","57","58","59" "60",61,"62","63","64","65","66","67","68","69" "70",71,"72","73","74","75","76","77","78","79" "80",81,"82","83","84","85","86","87","88","89" "90",91,"92","93","94","95","96","97","98","99" "100",101,"102","103","104","105","106","107","108","109" "110",111,"112","113","114","115","116","117","118","119" "120",121,"122","123","124","125","126","127","128","129" "130",131,"132","133","134","135","136","137","138","139" "140",141,"142","143","144","145","146","147","148","149" "150",151,"152","153","154","155","156","157","158","159" "160",161,"162","163","164","165","166","167","168","169" "170",171,"172","173","174","175","176","177","178","179" "180",181,"182","183","184","185","186","187","188","189" "190",191,"192","193","194","195","196","197","198","199"
My search on internet, to to see weather notepad++ suports this; brought me here. I have used TextPad and confirm that it supports find-and-replace within column selected block. Also TextPad is free for personal use.
Regex expreesion for last update file
Please help me out with a regex to find the last modified file/latest updated file in the folder. The files are in this manner: Test.2014_02_20 updated 13:00:23 Test.2014_02_21 updated 15:23:23 Test.2014_02_25 updated 21:24:23 Using regex we need to pick up the file Test.2014_02_25 updated 21:24:23 Thanks.
Through the comments from #Theox and #piet.t, OP has concluded that regular expressions were not the best tool to accomplish the task here. "You can use regexs to validate the format of the line (...)" - Theox "(...) the concept of ordering things by some criteria is way out of the scope of regex" - piet.t
Can Notepad++ save out search results to a text file?
I need to do quite a few regular expression search/replaces throughout hundreds and hundreds of static files. I'm looking to build an audit trail so I at least know what files were touched by what searches/replaces. I can do my regular expression searches in Notepad++ and it gives me file names/paths and number of hits in each file. It also gives me the line #s which I don't really care that much about. What I really want is a separate text file of the file names/paths. The # of hits in each file would be a nice addition, but really it's just a list of file names/paths that I'm after. In Notepad++'s search results pane, I can do a right click and copy, but that includes all the line #s and code which is just too much noise, especially when you're getting hundreds of matches. Anyone know how I can get these results to just the file name/paths? I'm after something like: /about/foo.html /about/bar.html /faq/2012/awesome.html /faq/2013/awesomer.html /foo/bar/baz/wee.html etc. Then I can name that file regex_whatever_search.txt and at the top of it include the regex used for the search and replace. Below that, I've got my list of files it touched. UPDATE What looks like the easiest thing to do (at least that I've found) is to just copy all the search results into a new text file and run the following regex: ^\tLine.+$ And replace that with an empty string. That'll give you just the file path and hit counts with a lot of empty space between each entry. Then run the following regex: \s+\n And replace with: \n That'll strip out all the unwanted empty space and you'll be left with a nice list.
maybe you need power of unix tools assume you have GNUWin32 installed in c:\tools\gnuwin32 than if you have replace.bat file with that content: #echo off set BIN=c:\tools\gnuwin32\bin set WHAT=%1 set TOWHAT=%2 set MASK=%3 rem Removing quotes SET WHAT=###%WHAT%### SET WHAT=%WHAT:"###=% SET WHAT=%WHAT:###"=% SET WHAT=%WHAT:###=% SET TOWHAT=###%TOWHAT%### SET TOWHAT=%TOWHAT:"###=% SET TOWHAT=%TOWHAT:###"=% SET TOWHAT=%TOWHAT:###=% SET MASK=###%MASK%### SET MASK=%MASK:"###=% SET MASK=%MASK:###"=% SET MASK=%MASK:###=% echo %WHAT% replaces to %TOWHAT% rem printing matching files %BIN%\grep -r -c "%WHAT%" %MASK% rem actual replace %BIN%\find %MASK% -type f -exec %BIN%\sed -i "s/%WHAT%/%TOWHAT%/g" {} + you can do regex replace in masked files recursively with output you required replace "using System.Windows" "using Nothing" *.cs
The regulat expression I use for this kind of problem is ^\tLine.[0-9]*:. And it works for me
This works well if you have Excel available and want to avoid using regular expressions: Ctrl+A to select all the results drag & drop the selected results to Excel Create a Filter on the 1st row Filter out the lines that have "(Blank)" on the 1st column Select the remaining lines (i.e. the lines with the filenames) and copy/paste them to another sheet or any wanted destination You could also Ctrl+A, Ctrl+C the search results, then use the Paste Option "Use Text Import Wizard" in Excel, say that the data is "Fixed width" and put one single break line after the 2nd character (to remove the two leading spaces in the filename during import), and use a filter to filter out the unwanted rows.