Help me to undersand regular expression
-
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 characternow if my interpretation is correct
why am I getting this as "final match "?
Waiting to connect to bluetoothd- bluetoothd is NOT followed by space - is should not match
- 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" -
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 characternow if my interpretation is correct
why am I getting this as "final match "?
Waiting to connect to bluetoothd- bluetoothd is NOT followed by space - is should not match
- 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"@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 ofWaiting to connect to bluetoothd. It shows how it has capturedbluetoothdfor 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.