5

I have a shapefile that has a column named "SBL" with string values that contain points (.) and hyphens (-). However, I want to remove these points and hyphens, but so far I haven't been able to.

have tried both replace and regexp_replace functions in QGIS, but I haven't been successful yet. Below is a sample of these values:

column value sample

Also below is the code I tried:

 regexp_replace("SBL", '.', '')
0

2 Answers 2

7

Try enclosing the . and - in square brackets for the regex:

regexp_replace("SBL", '[.-]', '')

Otherwise, you can chain replace like this:

replace(replace("SBL", '.', ''), '-', '')

If you actually want to replace them by a space, as implied by your remark "empty space", the replacement string should be ' ' (with a space between).

123.14-2-16.1 would become 123 14 2 16 1.

Using '' (no space) will simply remove the characters from the input string.

123.14-2-16.1 would become 123142161.

3

Your expression does not work as the period is a special character and therefore must be double-escaped:

regexp_replace("SBL", '\\.', '')

regexp_replace("SBL", '\\-', '')

OR

regexp_replace("SBL", '\\.|\\-', '')

but the best solution is to Matt

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.