Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QRegExp replece issue
QtWS25 Last Chance

QRegExp replece issue

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.0k Views
  • 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hi,

    I want separate the following string by "-" but unfortunately QRegExp doesn't match it

    rg

    (.*) - (.....) (.*)
    

    replace

    \1 - \2 - \3
    

    string

    KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM
    

    I expect to get

    KÜÇÜK OTOBÜS TAYO - S01E12 - GEL ARKADAŞ OLALIM
    
    Paul ColbyP 1 Reply Last reply
    0
    • M mbnoimi

      Hi,

      I want separate the following string by "-" but unfortunately QRegExp doesn't match it

      rg

      (.*) - (.....) (.*)
      

      replace

      \1 - \2 - \3
      

      string

      KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM
      

      I expect to get

      KÜÇÜK OTOBÜS TAYO - S01E12 - GEL ARKADAŞ OLALIM
      
      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @mbnoimi,

      The problem is that you don't have enough dots in the inner group - you have 5 dots, which matches 5 characters, but the input has 6 characters S01E12.

      # Doesn't work...
      paul@paul-XPS-13-9343:~$ echo 'KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM' | sed -re 's/(.*) - (.....) (.*)/\1 - \2 - \3/'
      KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM
      # Add another '.' and all is good :)
      paul@paul-XPS-13-9343:~$ echo 'KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM' | sed -re 's/(.*) - (......) (.*)/\1 - \2 - \3/'
      KÜÇÜK OTOBÜS TAYO - S01E12 - GEL ARKADAŞ OLALIM
      

      Cheers.

      M 1 Reply Last reply
      2
      • Paul ColbyP Paul Colby

        Hi @mbnoimi,

        The problem is that you don't have enough dots in the inner group - you have 5 dots, which matches 5 characters, but the input has 6 characters S01E12.

        # Doesn't work...
        paul@paul-XPS-13-9343:~$ echo 'KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM' | sed -re 's/(.*) - (.....) (.*)/\1 - \2 - \3/'
        KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM
        # Add another '.' and all is good :)
        paul@paul-XPS-13-9343:~$ echo 'KÜÇÜK OTOBÜS TAYO - S01E12 GEL ARKADAŞ OLALIM' | sed -re 's/(.*) - (......) (.*)/\1 - \2 - \3/'
        KÜÇÜK OTOBÜS TAYO - S01E12 - GEL ARKADAŞ OLALIM
        

        Cheers.

        M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        @Paul-Colby said in QRegExp replece issue:

        The problem is that you don't have enough dots in the inner group - you have 5 dots, which matches 5 characters, but the input has 6 characters S01E12.

        Indeed! Thanks

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          side notes:

          • if you are using Qt5, do not use QRegExp, use QRegularExpression
          • .{6} is safer and faster than ......
          • be careful with the greediness of * operators here

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          M 1 Reply Last reply
          2
          • VRoninV VRonin

            side notes:

            • if you are using Qt5, do not use QRegExp, use QRegularExpression
            • .{6} is safer and faster than ......
            • be careful with the greediness of * operators here
            M Offline
            M Offline
            mbnoimi
            wrote on last edited by
            #5

            @VRonin Thanks for advice,

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved