I'm trying to validate a string I use in one of my applications, and the structure of it is basically the same as linux command line arguments.
E.G
-m -b -s etc...
I'm basically trying to make the pattern;
- No space at the beginning but allow spaces inbetween words.
- There must be a space before a
-if it isn't the first-. - There should be no limit to how many you can enter as long as they fit the pattern. For example these would all be fine;
-m -fd -optionalbut something like this wouldnt be;-m-fd teststring
I managed to get as far as ^-[a-zA-Z]\s but I'm not sure how to make this repeat! This also doesn't work on flags longer than 1 character and also has some issues with spaces!
^-[^\s-][^-]*(?:\s-[^\s-][^-]*)*$and to extract, you may use(?<!\S)-[^\s-][^-]*