Regex Extract Number from a String with a Specific Pattern in Alteryx [Duplicate]

I have string like this which looks like a url

mainpath/path2/abc/PI 6/j

From the string I need to get the number along with PI

Main problem is the position of PI part wont be always the same. Sometimes it could be at the end. Sometimes at the middle.

So how can I get that number extracted using regex? I'm really stucked with this

2

It's as simple as using the RegEx Tool. A Regular Expression of /PI (\d+) and the Output Method of "Parse" should do the trick.

If you're using Alteryx... suppose your field name is [s] and you're looking for [f] (in your example the value of [f] is "PI")... then you could have a Formula tool that first finds /PI by first creating a new field [tmp] as:

SubString([s],FindString([s],"/"+[f])+1)

and then creating the field you're after [target]:

SubString([tmp],0,FindString([tmp],"/"))

From there run [target] through a "Text to Columns" tool to split on the space, which will give you "PI" and "6".

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest