Using RegEx to find a number in a string; I'm one off
- 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
I've read through the RegEx mastery article, which has been very helpful, bit I've hit a wall. I'm trying to get quantities out of a text string, and it works for some entries, but not all. Particularly, where it doesn't work, it truncates the leading number. Can someone make a recommendation on where I'm going wrong with the parse and how I can correct for it?
Parse showing $1 in the first condition, and $2 in the second
(^\d+)|(^.*\s*)(\d+)
Data
String to parse | Desired outcome | Actual outcome |
24 sets per case | 24 | 24 |
6CS | 6 | 6 |
Widgets 1/CS | 1 | 1 |
Many Widgets 20/CS | 20 | 0 |
Few Widgets -20/Case | 20 | 0 |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Regex_Replace([field],"\D","")
Will remove all other text.
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
Thanks Mark. Really appreciate the prompt reply! That works perfectly, as you pointed out, when there is only number.
Do you have any suggestions on what to do if there are multiple number sets in each input, but I'd always want to grab the last number set? For example, in both instances below, I'd want to return 50?
0.5 Parts 50/CS
8.5x11 size 50 box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
That will get that last number.
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
@MarqueeCrew ... Your solution will get the very last digit. If you want the whole number I would do something like,
workflow
Thanks,
P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Spot on, @PhilipMannering ! Thanks so much. Works like a charm.
And thanks again @MarqueeCrew
Support here is awesome, thanks to people like the both of you.
