TransWikia.com

Extracting part of string from field in QGIS Field Calculator?

Geographic Information Systems Asked by abrobia on August 23, 2020

I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression:

regexp_substr( "Text", '/(d*)_' )

based on this working example: Obtaining specific part of string from field in QGIS attribute table?

However, the expression does not give the desired result in my case:

enter image description here

Does anyone know any way to modify/accommodate the expression?

3 Answers

Since the number of characters is same, you can use substr() function on a new field as in the following expression:

substr( "Location" ,17,6)

enter image description here

In the above example I used Path instead of Location

Correct answer by ahmadhanb on August 23, 2020

A couple of issues - first, you don't need to escape (i.e. put a backslash before) the underscore. Your pattern also suggests that the digits follow immediately after a forward slash - which they do not, there is a w between them in each of your examples. If this is consistently a w, you could do:

regexp_substr( "location", '/w(d*)_' )

but in reality, if you're just trying to get every number before the underscore, you'd be sufficient with:

regexp_substr( "location", '(d*)_' )

As can be seen here:

enter image description here

Answered by asongtoruin on August 23, 2020

substr("location",16,(length("location")-1))

or

substr(substr("location",17,14),1,6)

that will return "W48535"

Answered by user168488 on August 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP