Could I ask the community for help with what should be a simple regex expression? Here is my RegEx tool settings for Tokenize:
(.+?)(?:-|$)
I am tokenizing my input to basically split at the 1st hypen. However, the tool is continuing to split with subsequent hypens and since I'm parsing names, hypenated last names are breaking. Here's an example:
string:
Customer Experience-Jonas-Smith, Teresa
Split 1:
Customer Experience
Split 2:
Jonas
I'm a n00b with regex so I have no idea how to fix this. Any assistance would be appreciated.
Solved! Go to Solution.
Hi @jay_chang
If you need to split into two columns, you can try the Parse method instead of the Tokenize method
Your statement would be: (.+?)-(.*)
Let me know if that helps.
Cheers!
Esther
(^.*?)-(.*), (.*$)
Specifically look for the first hyphen only(non-greedy)
Customer Experience
Jonas-Smith
Teresa
Second step, look for the comma. to break up the names
Jonas-Smith, Teresa
If hyphens will always occur after the 'Title', but not in every last name you are set.
Sorry, maybe I'm not typing it correctly but when I try your regex, I get "Error: RegEx (399): The Regular Expression in ParseSimple mode can have 0 or 1 Marked sections, no more."?
Also, I perhaps did not state my problem correctly. I want to split at the 1st hyphen and put the two tokens into 2 separate columns. The "last name, first name" portion (whether hyphenated or not) should be in a column while the descriptive should be in a separate column.
Hi @jay_chang,
As a leader in the Alteryx Community, I have the ability to identify & mark accepted solutions on behalf of community members - and recently did so on this thread. If you have any questions or concerns with the solution(s) I selected please let me know by replying to this post.
Both answers I marked are correct depending on how far you want to go with the RegEx Tool.
As the original author, you also have the ability to mark replies as solutions! Going forward, I’d encourage you to identify the solution or solutions that helped you solve your problem, as it's a big help to other community members. Learn more about Accepted Solutions here.
Thank you!
sorry, I got tied up in other work and could not get to this until today. I missed the part of the original solution where the poster suggested using Parse rather than Tokenize. Once I made that change her regex worked perfectly. I've marked the solution as correct. Thank you.
So the original reason I went with regex rather than text to columns was because I had situations where there were up to two hyphens prior to getting to the actual name (ie, "long group-important-muckamuck department-smith, john" so I was using the regex to count hyphens and parse differently based on that. It seems my data cleaned up so I don't need the regex as much but I think I'll keep it just in case. I might need to come back for more help at some point. 🙂
Thank you for your help!