5

I am fiddling with addresses, where I would like to remove the street number.

So far I found some solutions leading to explain how to get rid of the numbers but from the right side of the string:

Extract left part of field with regexp_substr after two specific charaters Removing string to the right of a character using QGIS Field Calculator? How to split string, removing digits keeping letters/words

as well as some options with replacing the parts of the string:

Replacing characters using an expression in QGIS How to extract part of string after '*', '~', '-' or '#' Replace using regular expression?

but I couldn't find either how to remove the number from the end of the string nor what is the definition of any number in QHIS expressions:

https://docs.qgis.org/2.8/en/docs/user_manual/working_with_vector/expression.html

I used these 2 codes but both didn't work as expected:

  right ( "Address L1", length("Address L1")-regexp_match("Address L1" ,'(_S\\d+)')-2)

  substr("Address L1",regexp_match("Address L1",'')+2)

because they take down just the first 2 characters some addresses are fine, other ones have additional space at the very beginning and others still keep some numbers. I need something, which would allow me to remove the stuff before the first space. Is it possible?

enter image description here

2
  • 1
    Correction: You want to remove the part before the first space, if that part consists of numbers. Otherwise you'd end up with facility instead of recycling facility. You know how to check for numbers, so use this as your condition, and then regexp_match() for spaces if there are numbers in the address.
    – Erik
    Mar 15, 2022 at 14:56
  • Yes, I want to get rid of everything before the first space. How can I do this?
    – Geographos
    Mar 15, 2022 at 15:09

1 Answer 1

8

To remove the numbers at the beginning of the string and its optional following space, you can use

regexp_replace(address,'^\\d*\\s?','')

^: beginning of the string
\\d: followed by any digit
*: found 0 or more time
\\s: followed by a space
?: found 0 or 1 time

2
  • 1
    Love the breakdown of the reg exp. Maybe I can remember it this time.
    – Erik
    Mar 15, 2022 at 15:23
  • Yes, so do I! It's a good way to understand it. @JGH how can we follow it by the second, third space, etc?
    – Geographos
    Mar 15, 2022 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.