Given the following regex:
^((?:\d+\s)?\w+(?:\s\w+)?)
which is working well to extract the first (up to) 2 words (preceded by a number, if there is one), how can I adapt it to included words that are hyphenated?
I tried adding \-
after the first w+
, but that only found the first half of the hyphenated word and broke the original functionality.
Some examples of valid matches are:
- 1 Two
- 3 Four Five
- Six-Seven-Eight
- Nine Ten
They are components of an address field and therefore, I suppose, might have an apostrophe somewhere too, how could I also check for that?
-
outside of[ ]
. – user1486147