Those all seem like good ways - what’s your criteria for “best”? If performance, you can check with BenchmarkTools. If you mean stylistically, that’s more about your own preference. In my own code, I had a similar problem and did
numbers = map(eachmatch(pat, text)) do m
Since it does it in one step without intermediate variables, but to me, it’s clearer than the broadcast or anonymous function versions. I don’t think any of these is more or less idiomatic Julia though.
Side note - I had to account for numbers like “1.233e5” in my code, which wouldn’t be matched by your regex. Maybe this doesn’t occur in your input, but I thought I’d mention it
My question was not about performances, but rather about shortness, readability and stylistic. I agree that your solution is a good candidat, but I would have liked another solution to be possible for getting all words.
The incomplete regex for Float was just an example, the question was mainly about getting all words in some text from a rexex.
I think the problem here is that eachmatch can’t be combined well with broadcast and parse, because eachmatch will return Base.RegexMatchIterator, which iterates through Regexmatch instead of directing returning the contents, so it can’t be passed to parse. Maybe you can define a new iterator which wraps Regexmatch and returns what you want, or you can find some other regex libraries and implement what you want in Julia?