How to find a date in row and copy to end of row
-
Fellow Notepad++ Users,
Could you please help me the the following search-and-replace problem I am having?
I am trying to take the date in a row and add it to the last field of each line.
Here is the data I currently have (“before” data):
F:\test\checks\543\005432.tif|5432|03/10/2022|d|deposit ticket|123
Here is how I would like that data to look (“after” data):
F:\test\checks\543\005432.tif|5432|03/10/2022|d|deposit ticket|12303102022``` To accomplish this, I have tried using the following Find/Replace expressions and settings Find What = `(\d+)/(\d+)/(\d{4})` Replace With = not sure Search Mode = REGULAR EXPRESSION Dot Matches Newline = CHECKED or NOT CHECKED
I’m not sure if I am on the right track or this is possible with find and replace. I want to find the formatted date, keep as is in that field but copy it to the end of each line.
Any help or guidance in the right direction would be greatly appreciated!Thank you.
-
Thank you for using the search/replace template! It made it so easy to help you!
The current find
(\d+)/(\d+)/(\d{4})
find the MM/DD/YYYY and puts them in three separate groups, which is exactly what you’ll need. You just need to extend the search to the end of the line, so that the replacement will be in the right place:- FIND =
(?-s)(\d+)/(\d+)/(\d{4}).*$
- the
(?-s)
makes sure.
won’t match the newline sequence - the
.*$
will extend the search to the end of each line
- the
Then, in the replacement, you will want to include the whole match (since you aren’t editing the first N characters of the line) with
$0
, then append the three groups of matched data using$1
,$2
, and$3
…- REPLACE =
$0$1$2$3
Then a single Replace will change one instance, or the Replace All will replace all instances.
(Please note, this regex is not repeat-safe: if you run it twice, the date will be re-appended twice)
----
Useful References
- FIND =
-
@PeterJones This worked perfectly, thank you!