I need to split up a string into single words, but there are some cases which should not be splitted.
An example for type I string
An example for degree II string
So every type | degree + I | II | III | IV | V should be kept as a string
The result of the example strings should be
['An', 'example', 'for', 'type I', 'string']
['An', 'example', 'for', 'degree II', 'string']
In my regex I have to search for type or degree, followed by space, followed by a string with characters I or V with maximum length of 3.
Those matches should not be splited.
consr regex = '/(type|degree)\s(I{1,3}|V{1})/' // <-- regEx is wrong as it is not working
const result = string.split(' ')
I'm not quite sure how to use the regex in combination with splitting in a way, that all matches are exceptions for splitting by space character.
(I{1,3}|V{1})means “either (from one to threeI) or (exactly oneV)”split()?(...). See jsfiddle.net/fu63Lyz5. I think you will also need to match that as whole words, hence, I added\bin the demo.