While i am solving the problems in the Tableau Community I see there are lot of Questions asked about how to extract numbers from a string

Consider we have a sample data like below

Text
nav129
nav65
nag836320.haba
nahy657qwh6s
fsjavua687q
gbha67w29
gbhfr456gde3
gbsh78
gbshw5
ghwf829348
hagtau0

If we have static pattern then we can write LEFT and right calculations in tableau to extract the number but here the use case is different All the numeric letters were appearing in between or end of the string.

While doing the research i ended up using the two types of RegExp to extract a number from a string. One is REGEXP_REPLACE and Other would be REGEXP_EXTRACT.

Using REGEXP_REPLACE
Syntax:REGEXP_REPLACE(string, pattern, replacement)
Description: Returns a copy of the given string where the matching pattern is substituted with the replacement string.

Bring the data to tableau and write the below calculation

Pattern : [a-zA-Z]
Explanation : [a-zA-Z] will match ASCII characters in the range from A to Z and in the range from a to z.
Replacement: “”

O/P:

Another way of achieving the same with different pattern using REGEXP_EXTRACT
Syntax: REGEXP_EXTRACT(String, Pattern)
Description : Returns the substring of the given string that matches the capturing group within the regular expression pattern. pattern requires one capturing group

Use the below calculation to extract numbers

Pattern : (\d+)
Explanation :

  • ( start a capture group
  • \d a shorthand character class, which matches all numbers; it is the same as [0-9]
  • + one or more of the expression
  • ) end a capture group

Output:

Hope this will helps

If you like this approach Plz share this blogspot.