I have this regex /\[\w+:/
Which I use to let me detect when a user types [something: into a text field (could be [place: , [info: , [user: , etc…).
I’d like to extend the regex to match characters after the : but not beyond a space (and not include the space either). For example,
var str = "This is a [place:car a great place to go!";
var matchedStr = str.match(REGEX);
The matchedStr value should be [place:car.
Thanks!
\Smatches anything that is not whitespace, so you could do\[\w+:\S+to get your desired match. This includes not just regular space but newlines, tabs, etc too. (which is probably what you want)You can also simply do a negative character class with a space in:
\[\w+:[^ ]+(which will include tabs/newlines/etc)