Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Help me to undersand regular expression
Qt 6.11 is out! See what's new in the release blog

Help me to undersand regular expression

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 812 Views 1 Watching
  • 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 Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Up front - I do not want to be accused of duplicating posts.
    I am really trying hard to learn how regular expression works - I am past the
    ...here it is - try it...

    I am trying to build, an expression to retrieve LAST word of QString.
    The original source had unwanted control characters I have managed to remove.
    The original source contains few " \n" - I do not see much problem with them.
    BUT the original source contains ellipsis...

    Here is how I interpret my current expression
    \w means match single ASCII character
    \w+ means match several ASCII characters
    (\w+)\s mean match several characters followed by space , hence word
    (\w+)\s* means match word followed by any character

    now if my interpretation is correct

    why am I getting this as "final match "?
    Waiting to connect to bluetoothd

    1. bluetoothd is NOT followed by space - is should not match
    2. the ellipsis .... shlud be "any character "
      it does not match and stops extracting from the
      the rest of the source.

    My guess is the expression
    ((\w+)\s*)*
    does not t take effect and I am not sure about more :any characters. ...

    I am looking forward for a discussion about how to interpret
    and correct the expression ,
    the actual C++ code is not subject of my concerns.

    DEBUG QString MainWindow_Bluetoothctl::SubRegularExpressionExt(QString, QString, int)
    DEBUG @line "6534"
    DEBUG TASK expression "((\w+)\s*)*"
    DEBUG TASK source "Waiting to connect to bluetoothd... bluetooth # bluetooth # Agent registered\n bluetooth # "

    DEBUG TASK captured match (line) "Waiting to connect to bluetoothd"
    Current extracted LINE (?) of text ((\w+)\s*)* "Waiting to connect to bluetoothd"

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Up front - I do not want to be accused of duplicating posts.
      I am really trying hard to learn how regular expression works - I am past the
      ...here it is - try it...

      I am trying to build, an expression to retrieve LAST word of QString.
      The original source had unwanted control characters I have managed to remove.
      The original source contains few " \n" - I do not see much problem with them.
      BUT the original source contains ellipsis...

      Here is how I interpret my current expression
      \w means match single ASCII character
      \w+ means match several ASCII characters
      (\w+)\s mean match several characters followed by space , hence word
      (\w+)\s* means match word followed by any character

      now if my interpretation is correct

      why am I getting this as "final match "?
      Waiting to connect to bluetoothd

      1. bluetoothd is NOT followed by space - is should not match
      2. the ellipsis .... shlud be "any character "
        it does not match and stops extracting from the
        the rest of the source.

      My guess is the expression
      ((\w+)\s*)*
      does not t take effect and I am not sure about more :any characters. ...

      I am looking forward for a discussion about how to interpret
      and correct the expression ,
      the actual C++ code is not subject of my concerns.

      DEBUG QString MainWindow_Bluetoothctl::SubRegularExpressionExt(QString, QString, int)
      DEBUG @line "6534"
      DEBUG TASK expression "((\w+)\s*)*"
      DEBUG TASK source "Waiting to connect to bluetoothd... bluetooth # bluetooth # Agent registered\n bluetooth # "

      DEBUG TASK captured match (line) "Waiting to connect to bluetoothd"
      Current extracted LINE (?) of text ((\w+)\s*)* "Waiting to connect to bluetoothd"

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @AnneRanch said in Help me to undersand regular expression:

      I am trying to build, an expression to retrieve LAST word of QString.

      I replied to just this question of yours in your other topic a couple of hours ago. I suggested you try

      Depending, you might find (\w+)\W*$ works for you (e.g. try it at https://regex101.com/).

      Did you try this? I have just set up a link for you: https://regex101.com/r/K2g0nS/1
      Please take the time to click on this link. It has that reg ex, and your input string of Waiting to connect to bluetoothd. It shows how it has captured bluetoothd for you. I don't know how to be any more helpful :)

      P.S.
      The ((\w+)\s*)* you talk about here. I suggested that to you in an earlier post when you asked for a reg ex to match all words in a string. Which it does. It is not for your newer request for just the last word.

      1 Reply Last reply
      1

      • Login

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