• Login
Community
  • Login

I need help with replacing different strings

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
search & replaceregex
4 Posts 4 Posters 1.1k 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.
  • T
    Theo Richel
    last edited by Aug 11, 2020, 4:10 PM

    I am working on a SRT (subtitles) file with time codes like this
    00:26.369,0:00:33.450

    However the comma in the middle needs to be replaced with space–>space

    When I do regex Find and replace I can find the piece before the comma with \d\d:\d\d.\d\d\d,

    But what do I set as replace string?

    \d\d:\d\d.\d\d\d -->

    gives dd:dd.ddd --> 0:00:33.450

    A P 2 Replies Last reply Aug 11, 2020, 4:34 PM Reply Quote 1
    • A
      astrosofista @Theo Richel
      last edited by Aug 11, 2020, 4:34 PM

      Hi @Theo-Richel

      Try this regex instead:

      Search: \d{2}:\d{2}\.\d{3}\K,
      Replace: \x20

      Have fun!

      1 Reply Last reply Reply Quote 1
      • P
        PeterJones @Theo Richel
        last edited by PeterJones Aug 11, 2020, 5:18 PM Aug 11, 2020, 5:17 PM

        @Theo-Richel said in I need help with replacing different strings:

        \d\d:\d\d.\d\d\d,
        But what do I set as replace string?
        \d\d:\d\d.\d\d\d --> gives dd:dd.ddd --> 0:00:33.450

        Thanks for showing what you tried. We really appreciate it when people show their effort when asking questions here. See my footnote for more hints on asking questions successfully.

        For replacement strings, \d doesn’t mean “match any digit”, it means “give me a literal d”. If you want to re-use text from your match in your substitution, it either needs to not be part of the “match” (which is what @astrosofista’s \K does: it requires the stuff before the \K to be present, but it’s not considered part of the “match”), or you need to store the data in a group. For your desire to change

        00:26.369,0:00:33.450
        

        to

        00:26.369 --> 0:00:33.450
        

        I might use

        • FIND = (\d\d:\d\d.\d\d\d),
        • REPLACE = $1\x20-->\x20
          • $1 means the contents of the first group (the first set of parentheses in the match)
          • Note: the \x20 is another way of writing the space character; it makes it easier to copy-paste the expression from the forum into your Replace dialog. If you’re manually typing the regex, you could just have spaces instead of the \x20

        edit: forgot the footnote; added.
        ----

        Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipbpard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

        1 Reply Last reply Reply Quote 1
        • O
          Olivier Thomas
          last edited by Aug 11, 2020, 7:08 PM

          This is not a valid srt timecode.
          Whatever you do, it won’t work.
          00:26.369,0:00:33.450

          The correct code is as follows:
          00:00:36,833 --> 00:00:39,291

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