Regex to pull leading numbers with varying lengths and delimiters?
- 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
Howdy,
Tried searching the boards for a similar issue and don't see one that is similar to this. Hoping someone can assist as I'm a Regex newbie.
I basically have a bunch of support documents that have a identification code up front followed by the name of the support. These codes can vary in length and the characters that follow the digits can also vary. Here's a rough example:
File naming conventions | What I need to pull |
3340-Balances-20201204 | 3340 |
700132099 SupportPackage | 700132099 |
8129005_12-04-2020 Module | 8129005 |
32603260CashValues | 32603260 |
All I'm after are the codes at the front. I'm having a heck of a time with this as my trusty ol' text to columns doesn't seem to work super well when the delimiter can be an underscore, space, hyphen, or not exist at all. Any thoughts?
Thanks in advance, friends!
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@TGow
How about this one?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I think (\d+) which looks for any amount of digits in the front of the field and puts it into a new column will do what you need:
This RegEx editor site
is really helpful with POSIX regex syntax.
Sarah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here's a quick formula:
regex_replace([field],"(\d+)\D.*","$1")
starting numbers get caught.
cheers,
mark
Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi all, these all look like they'll work!
Thank you Qui and treepruner for the regex tool examples, it looks like the solution is fairly simple! I definitely need to spend some time learning this a bit more. In that vein, thank you for the link treepruner. I will give it a look!
Thank you for the formula MarqueeCrew. I knew the formula tool can do a lot of Regex magic but have never given it a shot. I'll definitely look at ways to try and integrate these in my workflows once I have a better handle on the subject.
I appreciate you all taking the time to assist 😀
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks for the opportunity that you gave us to help show you alternative ways of solving using Alteryx.
cheers,
mark
Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
