Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to only keep the numbers and . in a string?

davidi123
5 - Atom

Hi All, I want to perform this type of filtering in Regex or filter tool. if there's an "R" before the numbers, then keep R, numbers, and ".", but remove all letters after numbers. Appreciate all th

 

I want it to be like: 

inputs:  

123.3QBS

R1232

1234

1234.2

R123.2ABC

 

outputs:

123.3

R1232

1234

1234.2

R123.2

4 REPLIES 4
Prometheus
12 - Quasar

I like to use regex101.com to test my regular expressions. You can use the Parse function in the RegEx tool to accomplish this.

 

Here's what I came up with: (^R*\d+\.*\d*).*

 

Anything inside the parentheses is going to get be kept. Everything outside is not going to be parsed. I'm identifying the "R" at the beginning of the word by using the "^", then R is quantified using "*", which means that it occurs zero to infinity times. After that, "\d" represents any digit and it's quantified using "+" which means it occurs at least once to infinity times. Then comes the "\." which represents the actual period, instead of what "." represents in a regular expression and it's quantified by "*" which means that period occurs zero to infinity times. The last part is "\d*" which signifies that I'm looking for between no digits and infinity digits and I'm not looking for anything else after it. Don't forget to rename your field from "RegExOut1."

 

Regex101.com is amazing and it's a great site to use when you're learning RegEx. Go ahead and test it out yourself and let me know if you have any questions.

flying008
15 - Aurora

Hi, @davidi123 

 

Expression:

[[:alpha:]]+?$

 

录制_2023_07_18_08_03_20_304.gif

caltang
17 - Castor
17 - Castor

To contribute to the discussion, here is another way to do it in REGEX:

(\d+\.\d+|\d+\.?\d*[A-Za-z]+|\d+)

 

image.png

 

Hope this helps too @davidi123 !

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
sparksun
11 - Bolide

Here is my solution:

 

forum.jpg

Labels