Sathish
Sathish

Reputation: 191

Regular expression to find strings between special characters using QRegExp

I want to match the Property Name and Property value in the string below

#Property Name : Property Value

The Property Name and Property Value are single/multi-worded sentence with numbers and spaces only. No special characters in them.

I tried with (?<=#)(.*):(.*?) but it is not working. I read through many of the questions in this website and tried them, but none seemed to work.

I expect the answer to use QRegExp (RegEx class of Qt) of qt4

Upvotes: 0

Views: 703

Answers (2)

Marek R
Marek R

Reputation: 38062

IMO this is better:

^#\s*([^:]+?)\s*:\s*(.*?)\s*$

https://regex101.com/r/pW3wV4/3

See this to why my solution is better (same reg exp but more test cases).

Upvotes: 1

Amen Jlili
Amen Jlili

Reputation: 1944

Try the following regex

^#([a-zA-Z0-9 ]*) : ([a-zA-Z0-9 ]*)$

demo here: https://regex101.com/r/gS7rF5/2

Upvotes: 1

Related Questions