Bug report #3960

QgsSearchTreeNode fails to handle regex string correctly.

Added by Nathan Woodrow almost 13 years ago. Updated almost 13 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:-
Affected QGIS version: Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied: Resolution:
Crashes QGIS or corrupts data: Copied to github as #:13964

Description

If using regex string in a QgsSearchTreeNode and QgsSearchString the parser fails to recognize the regex string correctly.

Example running the following in the QGIS Python console:

qgis.console.clearConsole()
layer = qgis.utils.iface.mapCanvas().currentLayer()
search = QgsSearchString()
search.setString("LandUseCode ~ '\\d{2}'")
tree = search.tree()
tree.makeSearchString()
rightnode = tree.Right()
value = rightnode.valueAgainst(layer.pendingFields(),layer.selectedFeatures()[0])
value.string()

yields:

>>> layer = qgis.utils.iface.mapCanvas().currentLayer()
>>> search = QgsSearchString()
>>> search.setString("LandUseCode ~ '\\d{2}'")
True
>>> tree = search.tree()
>>> tree.makeSearchString()
PyQt4.QtCore.QString(u'(LandUseCode ~ ?{2})')
>>> rightnode = tree.Right()
>>> value = rightnode.valueAgainst(layer.pendingFields(),layer.selectedFeatures()[0])
>>> value.string()
PyQt4.QtCore.QString(u'?{2}')
>>> 
>>> 

The \\d part of the regex is replaced with a ? and this trips up the checkAgainst() method of QgsSearchTreeNode.

History

#1 Updated by Nathan Woodrow almost 13 years ago

  • Status changed from Open to Closed

It seems you need to use \\\\ with regex in Qt. So this is not really a bug and I'm going to close it.

Also available in: Atom PDF