It's uncertain whether using something like (^|\s)
and (\s|$)
is advisable at first. It may require some careful consideration to fully grasp the regex pattern. Complex regex patterns can often be confusing and difficult to understand, which is not ideal.
If you're looking to match words that start with "mso", regardless of case sensitivity, a possible approach could be:
"class1 MsoClass2\tmsoclass3\t MSOclass4 msoc5".match(/\s?(mso[^\s]*)\s?/ig);
This will give you:
[" MsoClass2 ", "msoclass3 ", " MSOclass4 ", "msoc5"]
It's close to what you requested, with some slight differences in whitespace.
Alternatively, a simpler solution could be:
"class1 MsoClass2\tmsoclass3\t MSOclass4 msoc5".match(/(mso[^\s]*)/ig);
Providing you with:
["MsoClass2", "msoclass3", "MSOclass4", "msoc5"]
Without any extraneous whitespace.
This approach is easier to comprehend and more reader-friendly as well. :-)