I dont really understand how regex works
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
regexIm using the regex parse function. I got my result.
But I dont understand how it works.
I have a set of data that looks way like this more or less.
Company Name | RegexExOut1 | |
Ali Abu Adik Transport & Brokerage (S) Pte Ltd (1012342-H) | Ali Abu Adik Transport & Brokerage (S) Pte Ltd |
For most of the case, the result comes out smoothly but the Johnhot gone haywire
Company Name | RegexExOut1 | |
Johnhot YTM Pte Ltd (Ula YTM Trans's Specialist (Singapore) Pte Ltd | Johnhot YTM Pte Ltd (Ula YTM Trans's Specialist |
Below is my setting for Regex
Bare in mind I do not understand what I am doing and how does it work. Can someone explain to me what is wrong and how I hit the jackpot?
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
What output are you looking for? I think your RegEx is giving you everything up to the final opening bracket.
In RegEx, brackets mark out groups. (.*) at the start is the marked group that will be returned by your parse function. Within that, . represents any character and * indicates 0 or more of them. On its own, that would return everything from the input.
\ is an escape character, so \( and \) indicate that you're looking for actual brackets in the input and not marking out another group. \s represents white space characters.
Square brackets are used to contain a set of characters you are looking for, e.g. [a-z] would match a single lower case character. You have [^)]*, where ^) represents any character except ).
So your whole expression (.*)\s\([^)]*\) will match a space followed by anything other than ) contained in brackets, then return anything from before that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Not strictly needed here but since things are breaking I would add a ".*" at the end of your expression to pick up the rest of the string.
(.*)\s\([^)]*\) .*
@Christina_H did a wonderful job breaking things done for you. 👏 Since I imagine you may be newer to Regex let me point you to a page that I love using if you haven't already found it for yourself.
This site will let you test Regex and on the right hand side it explains each part of it.
See below how your expression doesn't match the full string for JohnHot. The highlight portion is what's matched and the white portion is unmatched. The Green is the part you are parsing out and the Blue is everything else that matched.
Adding the .* at the end now matches the whole string: (This may fix your issue in Alteryx.)
I wish I could help more, but even with your original expression its not broken for me in Alteryx. (Should work on your end as well)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
The expression
(.*) \(
does the same thing in these cases - capture everything up until the last space + open bracket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
