Shortly after I wrote about extracting numbers from text strings, Winston Snyder at dataprose.org wrote a detailed article about using “regular expressions” to separate text from numbers in any string. I have adapted his routine for the same purpose as in the previous post, that is to extract a single numerical value from a text string. The regular expressions approach has two main advantages:
- The same function can be used to extract numbers from the left, right, or middle of a text string.
- No delineators are required.
The only drawback is that if the text string contains more than one number the function will concatenate them if they are integers, or return zero if they both have decimals.
This function is only scratching the surface of what can be done with regular expressions. For more details and links see dataprose.org.