mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-02 00:02:12 -05:00
Fix regexp_substr expression function returning whole match instead of captured group
This commit is contained in:
parent
01d1be9d70
commit
9bfb3f31ee
@ -1205,7 +1205,16 @@ static QVariant fcnRegexpSubstr( const QVariantList &values, const QgsExpression
|
||||
if ( match.hasMatch() )
|
||||
{
|
||||
// return first capture
|
||||
return QVariant( match.captured( 0 ) );
|
||||
if ( match.lastCapturedIndex() > 0 )
|
||||
{
|
||||
// a capture group was present, so use that
|
||||
return QVariant( match.captured( 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// no capture group, so using all match
|
||||
return QVariant( match.captured( 0 ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -961,6 +961,8 @@ class TestQgsExpression: public QObject
|
||||
QTest::newRow( "regexp_substr non-greedy" ) << "regexp_substr('abc123','(\\\\d+?)')" << false << QVariant( "1" );
|
||||
QTest::newRow( "regexp_substr no hit" ) << "regexp_substr('abcdef','(\\\\d+)')" << false << QVariant( "" );
|
||||
QTest::newRow( "regexp_substr invalid" ) << "regexp_substr('abc123','([[[')" << true << QVariant();
|
||||
QTest::newRow( "regexp_substr ignored part" ) << "regexp_substr('abc123','c(.)')" << false << QVariant( "1" );
|
||||
QTest::newRow( "regexp_substr no capture group" ) << "regexp_substr('abc123','c\\\\d')" << false << QVariant( "c1" );
|
||||
QTest::newRow( "regexp_matches" ) << "array_get(regexp_matches('qgis=>rOcks;hello=>world','qgis=>(.*)[;$]'),0)" << false << QVariant( "rOcks" );
|
||||
QTest::newRow( "regexp_matches empty custom value" ) << "array_get(regexp_matches('qgis=>;hello=>world','qgis=>(.*)[;$]','empty'),0)" << false << QVariant( "empty" );
|
||||
QTest::newRow( "regexp_matches no match" ) << "regexp_matches('123','no()match')" << false << QVariant();
|
||||
|
Loading…
x
Reference in New Issue
Block a user