I am looking for a regex able to capture all the words in a string.
I have below input strings
- JOHN SMITH MR
- JOHN MR
- J MISS
Expected output
- {"JOHN", "SMITH", "MR"}
- {"JOHN", "MR"}
- {"J", "MISS"}
I have written the regex below which is working perfectly fine but it is not working for input string 2 and 3. The input string should only have alphabetical characters (no numbers or special characters).
((?:[a-z]*[a-z]+)).*?((?:[a-z][a-z]+)).*?((?:[a-z][a-z]+))
If the input string contains numbers like JOHN 12345 then the regex should not capture anything.
Could you please help me to improve my regex to capture the expected result?