Search code examples
jqueryregexregular-language

Regex for # and text between # and trailing whitespace


I am trying to get regex for:

  • Get "#" and all text between "#" and trail ending "\t"(whitespace).

So far I have:

/#[a-zA-Z0-9]\t/

This seems wrong? What can I do to fix it?


Solution

  • If by whitespace you mean actual whitespace (that is spaces, tabs, etc), then this does it:

    /#\S+/
    

    (\S is equivalent to [^\s])

    If you however meant tabs, when you wrote whitespace, then this:

    /#[^\t]+/