3

I have a shapefile, which is a parcel map. Its table of contents has a column containing the addresses of several buildings. Some of the addresses hold directional information (i.e. n, s, w, e).

The problem is that there is no space between house numbers and the directional information, which might cause issues later in the project. Below are some examples:

  • 100W GERMAN ST
  • 100W HIGH ST
  • 100W WASHINGTON ST

How can I add a single space, i.e. 100 W instead of 100W? I am assuming that this can be done using regular expression, however since I have not faced such an issue before, I am not sure what exactly the regular expression should be.

2
  • So you want 100 W instead of 100W, am I right ?
    – Taras
    Commented Jun 15, 2022 at 20:28
  • Correct. Can that be done using Regex or any other way? Commented Jun 15, 2022 at 20:32

2 Answers 2

6

Regex case assertion is what you need, use this expression in the Field Calculator:

regexp_replace("field_name", '(?<=[0-9])(?=[N,W,S,E])', ' ')

Replace field_name with a field containing the addresses.

0
1

Another option:

 regexp_replace("fieldname",'(.*\\d)([EWSN])','\\1 \\2')

This looks for a number of any length, followed by one of the letters EWSN and introduces a space before E,W,S, or N.

Your Answer

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

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