I am trying to remove the last piece of my string in QGIS.
I want to delete the E10 from the end.
I tried both:
How to easily edit attribute data using Regular Expressions?
regexp_replace("UPRN", 'E*', '')
as well as
regexp_replace("UPRN", 'E10', '')
but I get only pure 1.000 value.
In this approach:
Removing string to the right of a character using QGIS Field Calculator?
I tried:
regexp_replace("UPRN", ('E*'), '')
and
regexp_replace("UPRN", ('E*'), '')
but it still throws 1.0000 only.
What am I missing here?
Best Answer
You're missing the
.
after theE
; in other words, the token for a character following theE
:There are a lot of ways to make the pattern more surgical. You could use
\d
if you want to match anE
and any digits that follow it:You can also use + rather than * to ensure you only match to literal
E
that are actually followed by at least one digit:Just depends on how much variation there is in your strings.
P.S. It also wouldn't surprise me if you're saving the results in a float, rather than a string field. Might explain the case where you get 1.000 as your result