It seems to me you are trying to do like a match for any number.
So you would have to set it up to match any of those as well.
Really, just do tests in the input output views. So:
print( string.match(“Hello!!! I am another .123456.1243. string.”, “%d*[%.%d]%d*”) )
Then you can speed test them.
It seems to me that your code isn’t right.
You want Magic Number All proceeding numbers, then Magic . then Magic numbers proceeding.
So “%d*%.%d*” So all numbers in a sequence, full stop, all numbers in a sequence. 1234.2345
But that will only match decimals with a number before the decimal.
For say “.54” where the 0 isn’t included, you would have to match “%.%d*”
For a whole number, you would have to match “%d*”
But you would look for full decimals first, if it doesn’t find any, then search for decimals without the 0. If it doesn’t find any, search for the whole number. If it doesn’t find any, return “There are no numbers in this string.”
That’s what I would do.
Just tested this
print( string.match(“Hello!!! I am .321.121 another string.”, “%.%d*%.%d*”) ) – Set
But you will have to search for more than one and compare them. You can always store the result and remove check if there are more than 1 point then and if the first character is a point, then remove it.
You can also clean the string up first by removing any matches from the string if it’s not a number. So for instance a sentence. If it is a . without a number after it, then remove it.
It’s a lot of work but you can get it done in about 20-50 lines of code I believe.