remove non numeric characters from the beginning or end of a string (not the middle)
- 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
Hi!
Regex question. How can I remove non numeric characters from the beginning or end of a string (but not from the middle)?
e.g. before:
65x
2.5
si98
a99a
3-
I want the result to be:
65
2.5
98
99
3
This is important because I do not want to lose the decimals, e.g. 2.5 should not become 25
Solved! Go to Solution.
- Labels:
- Regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You can use Regex here to keep only numbers (and periods for that matter since you have decimals)! You’d use something along the lines of \d+\.?\d+
try Regex_Replace([Column], “.*(\d+\.?\d+).*”, “$1”) in a Formula for example! I can test once in front of a computer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If you only want to keep numbers and decimals, try
[0-9]|\.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you both! I think I have managed a sort of inelegant workaround with:
REGEX_Replace([Yrly Volume], "[^0-9.]", "")
but then I also had to do a follow up formula:
if [Yrly Volume] = "." then 0 else [Yrly Volume] endif
because someone has entered a single full stop in one of the records!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
That looks like it would work - nice solution @RBF !
Hoping my answer gave at least some inspiration :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Yes, indeed you both helped! Sometimes you just need someone to help you think through a problem! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Awesome! Can you mark our responses as solutions then? You can even mark your own answer :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@RBF including ours if you don't mind! Thank you in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@RBF you could use the data cleanse tool and select remove letters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@aatalai there are non-letter instances like "-" to be mindful of! And we can't select the cleanse punctuation in that tool because then it would remove the decimal too 😥
