I am trying use a regular expression in JavaScript to match instances of the word ‘icon-‘ in a string and return the entire attached word up to the delimiter (space). An example of the string would be
ui-grid-ico-sort icon icon-up ui-icon-asc icon-user ui-icon ui-icon-triangle-1-n ui-sort-ltr
In this case I am trying to match only ‘icon-up’ and ‘icon-user’.
So far I have tried \bicon- which appears to match every instance of icon- regardless of its placement in a word (4 matches) and \bicon-[^'”]+ which returns 1 match of everything after the first instance of icon-
matches all words that start with
icon-up to the next whitespace character.You will need to remove a leading space character, if present. There is no other way because JavaScript doesn’t support lookbehind assertions.
Explanation: