Regex to extract string and number
- 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
Help me please to create a regex to extract string and number from a string like 906D3829.22 into 906 D 3829.22
So far, I have been able to extract numbers using [\d.]+ into 906 3829.22
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
This should work for any number/string/number combination: ([\d]+)([[:alpha:]]+)([\d].+)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@kathleenmonks Does that last full stop need to go inside the square brackets?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If you use a formula tool with:
Regex_replace([Field], '(\d+)(\D+)([0-9\.]+)', '$1 $2 $3')
I believe that should give you the output requested above in a single field. Not at my laptop with an Alteryx install to double check this, though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@DataNath You don't need to escape that full stop / period.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks for the tip @PhilipMannering! Is that always true when including characters you'd normally escape within a group?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@PhilipMannering Good catch. It works as is for this particular case, but the decimal identifies "any single character" so it could result in other characters slipping through. You could change it to: ([\d]+)([[:alpha:]]+)([\d\.]+) to only pick up the decimal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@DataNath Oooh.. that's a good question. I think that is the case, yes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Use a regex tool and select the parse mode -- input this in
(\d+)(\D+)(.+)
What this is doing is creating 3 groups
Group 1 - digits up to a non digit char
Group 2 - non-digit character
Group 3 - everything else after group 2
Please make sure to mark a solution!
Thanks
