简体   繁体   中英

Regex extract mutliple values

I have a string that looks like this: "60% Bob Peterson, 35% Jake Peter Sullivan, 5% Maria Teresa".

I want to write a regex to grab the first word after %:

Desired output: "Bob, Jake, Maria"

So far I came up with this: %\W*(\w+)

But it is only grabbing the first instance. I need to grab all instances and print them separated with a comma.

You can use Python inside Tableau using TabPy

import re

string = "60% Bob Peterson, 35% Jake Peter Sullivan, 5% Maria Teresa"
result = re.findall(r'\d+%\s(\w+)', string)
print(', '.join(result))

In the tableau, you cant loop the regex check, hence use Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM