Search code examples
regexqtqregexp

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


Solution

  • 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).