Search code examples
regexword-boundary

Regex: word boundaries


I have to search words containing capitalized letters or numbers.

I use \b[^ ]*[A-Z0-9]+[^ ]*\b, however instead of [^ ] i would like to use [^\b], but this selects all the phrase...

ThisisSometext, that hass0menUm8ers, likeBoeing-380orRNA-78.ThatisGREAT!


Solution

  • You may use \w* for matching zero or more word characters.

    \w*[A-Z0-9-]+\w*
    

    or

    \S*[A-Z0-9]+\S*
    

    And note that you can't include \b, \B inside a character class. You could achieve the result without including the both inside a character class through some other ways. \S* matches zero or more non-space characters.

    DEMO