2

I have a 'name' field with composite name; numbers and words e.g. "1237, Café"

I managed extract the part number with Field Calculator and make a new field (see 1) with this expression

left( "Name" , strpos( "Name" ,'\s') - 1)

But I can´t find the way to extract the part names - just words!

If I use this

regexp_replace( "Name" , '\W', ' ')

Creating a new field result only fields with numbers...(see 2)

EDITED: correction; the results with only numbers; if the type is "whole number (integer)"!!

Updating the 'name' field, result the same fields only without ','... e.g. "1234 Café"

enter image description here

  • 2
    To get the words only, you could try something like: regexp_replace( "name",'[\\d,]','') – cm1 Jan 17 '18 at 20:55
3

RESOLVED

Example: "1237, Café"

  1. To extract the number to a new field 'addr_num'

In the Field Calculator

  • New Field: 'addr_num'
  • Type: Whole number (integer)
  • Lenght: 10

Expression:

left( "Name" , strpos( "Name" ,'\s') - 1)

[see post]

Result "1237"

  1. To extract the 'name' part to a new field 'new_name'

In the Field Calculator

  • New Field: 'new_name'
  • Type: Text (string)
  • Lenght: 80

Expression:

regexp_replace( "name",'[\d,]','')

Result: " Café"

Credit: @cm1

But to trim spaces:

trim( regexp_replace ( "name",'[\d,]','') )

Result:

"Café"

REGEX:

\s - whitespace

\d - digit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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