• Login
Community
  • Login

How to find a date in row and copy to end of row

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 731 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Ashley Hoogenboom
    last edited by Ashley Hoogenboom Oct 6, 2022, 5:21 PM Oct 6, 2022, 5:19 PM

    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.

    P 1 Reply Last reply Oct 6, 2022, 5:47 PM Reply Quote 1
    • P
      PeterJones @Ashley Hoogenboom
      last edited by Oct 6, 2022, 5:47 PM

      @Ashley-Hoogenboom ,

      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

      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

      • FAQ: Where to find regular expressions (regex) documentation
      • Notepad++ Online User Manual: Searching/Regex
      A 1 Reply Last reply Oct 6, 2022, 10:18 PM Reply Quote 3
      • A
        Ashley Hoogenboom @PeterJones
        last edited by Oct 6, 2022, 10:18 PM

        @PeterJones This worked perfectly, thank you!

        1 Reply Last reply Reply Quote 0
        2 out of 3
        • First post
          2/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors