You can use the \W
(upper case W) to match any non-alphanumeric characters.
If using regexp_replace() it seems you need to escape the backslash, so it becomes \\W
(thanks, Joseph!)
For example
regexp_replace( '=+&hello%%£world','\\W+','_')
returns
_hello_world
If using the python equivalent function re.sub(), you probably won't need to escape the backslash.
You can search for any char (.*
), followed by a dot (\\.
), followed by a number that we capture ((\\d+)
) followed by any char. Replace with the captured number.
regexp_replace('354ab.27xyz789','.*\\.(\\d+).*','\\1')
or you can search for a dot followed by a number that we capture
regexp_matches('354ab8.27xyz789','\\.(\\d+)')
Original answer for a pattern of (1 character)(1 character)(dot)(number with 1 or more digits)
:
Instead of searching for the exact pattern, you can search for what is not a number and replace it with an empty string:
regexp_replace('ab.27','[^0-9]','')
or you can look for numbers only
regexp_matches('ab.27','(\\d+)')
But if you are always having the same pattern, you can just take all chars but the first 3 ones:
right('ab.27',length('ab.27')-3)
Best Answer
QGIS, uses QT's QRegularExpression. which is itself just PCRE.
You can see the use of it in src/core/qgsexpression.cpp
Note one Gotcha with the QT C++ implementation is that you have to escape
\
,Another but very minor non-gotcha, is