QGIS – Removing Part of String from the Right

attribute-tableexpressionqgisregular expressionstring

I am trying to remove the last piece of my string in QGIS.

enter image description here

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 the E; in other words, the token for a character following the E:

regexp_replace(string, 'E.*', '')

enter image description here

There are a lot of ways to make the pattern more surgical. You could use \d if you want to match an E and any digits that follow it:

regexp_replace(string, 'E\d*', '')

You can also use + rather than * to ensure you only match to literal E that are actually followed by at least one digit:

regexp_replace(string, 'E\d+', '')

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