Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-36660

Regular expressions fail to match escaped operator \+ when enclosed with \b

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.2.0
    • Core: Other
    • None
    • MSVC 2013, Windows 8.1

    Description

      I have a string "foo + bar". I attempt to write a regular expression matching the free-standing "+" operator.
      However, my initial attempt QRegularExpression("\\b\\+
      b") didn't succeed — it fails to match to the said string.

      If I replace "
      +" with "a", it works. If I replace "
      b" with " " (space), it works (but does different thing than I wanted). So apparently both parts are fine on their own, they fail only when composed together.

      Please consider the following source code snippet:

      	const QString textA = "foo a bar";
      	const QRegularExpression regexpA("\\ba\\b");
      	const QString textPlus = "foo + bar";
      	const QRegularExpression regexpPlus("\\+");
      	const QRegularExpression regexpPlusEnclosed("\\b\\+\\b");
      	assert(regexpA.globalMatch(textA).hasNext()); // OK
      	assert(regexpPlus.globalMatch(textPlus).hasNext()); // OK
      	assert(regexpPlusEnclosed.globalMatch(textPlus).hasNext()); // FAILURE
      

      I believe all three matches should succeed, while the third one fails.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            mwu Michał Urbańczyk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes