1

I have a string field that I want to extract only the digits example: (1,500 m2 --> 1500) QGIS

example

I've tried with regexp_substr( "location", '(\\d*)' ) to remove all after the blank space, but I need also the ones who have a comma to only extract the digits, the first to rows works fine for me, but the two after doesn't (1,500 M2 and 1,456 m2)

1

Another regex expression to use is the following:

 regexp_substr("FieldName",'\\d,+\\d+|\\d+')

Substitute "FieldName" with the name of the field that you want to extract the digits from. "descriptio" in your case.

The above will extract digits with comma or digits without comma.

enter image description here

2
  • Thank you!, this worked, but I realized I had blank spaces as well besides commas, is there an expression to solve that too? – Juan Millan Mar 19 '20 at 15:40
  • @JuanMillan I have not try this but you can give it a try: regexp_substr("FieldName",'\\d , \\d+|\\d,+\\d+|\\d+') – ahmadhanb Mar 20 '20 at 3:04
0

Try using the regular expression provided in this answer.

regexp_substr( "location", '\b\d[\d,.]*\b' )
0

Probably a bit old-fashion approach but also gives a desired output using the follwoing expression

to_int(replace(left("text", regexp_match("text",' ') - 1), ',', ''))

example

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.