5

What are the right functions and formulas with the field calculator to delete "alphabet" or "number" inside a field?

Let me be clear. I want to be able to delete "alphabetic letters" or "numbers" inside my records (see the image). I've used replace, left, substr functions, but they don't make any difference between "alphabet" and "number".

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Yems
  • 51
  • 5
  • 4
    Please edit your question to show us a sample on how the texts in the attribute table are look like. – ahmadhanb Sep 02 '20 at 23:27
  • when extracting apply: for integers use to_int(regexp_substr("field_name", '(\\d+)')) and for symbols to_string(regexp_substr("field_name", '[A-Za-z]+')). when deleting use regexp_replace()instead. – Taras Sep 04 '20 at 11:46
  • @Taras, your formulas are working!!! Tank you very much for your help. – Yems Sep 05 '20 at 16:01

2 Answers2

4

To split your field into subfiels, i.e. "alphabetic" or "numeric" apply:

for integers:

to_int(regexp_substr("field_name", '(\\d+)'))

that will give you '199' from '199 (ME)'

for symbols:

to_string(regexp_substr("field_name", '[A-Za-z]+'))

that will give you 'ME' from '199 (ME)'


References:

Taras
  • 32,823
  • 4
  • 66
  • 137
2

Use this expression to get only the numers and replace [0] with [2] to get only the alphabetic letters:

regexp_matches(name,'(\\d+)*(\\s+|\\W+)*(\\p{L}+)*')[0]

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208