I have three possible forms that will go through a regular expression, and I’d like to match them all.
text1
text1 text2
text1 text2 ;text3
I’ve got so far (.*?)(?:\s)(.*) working for 'text1 text2', but I able to handle all three cases if the semicolon is present. Any ideas?
The following should work, it would also put ‘text1’, ‘text2’, and ‘text3’ into the correct groups:
See it working: http://www.rubular.com/r/IyPyF3wXLx
Here is an explanation:
The optional groups in the middle allow your regex to match text2 and text3 if they are present, but still match if they are not.