I am trying to find words starts with a specific character like:
Lorem ipsum #text Second lorem ipsum. How #are You. It's ok. Done. Something #else now.
I need to get all words starts with "#". so my expected results are #text, #are, #else
Any ideas?
Match a word starting with # after a white space or the beginning of a line. The last word boundary in not necessary depending on your usage.
The parentheses will capture your word in a group. Now, it depends on the language how you apply this regex.
The
(?:...)
is a non-capturing group.Try this
#(\S+)\s?
Search for:
So try this:
Or in C# it would look like this:
Output:
Code below should solve the case.
/\$(\w)+/g
Searches for words that starts with$
/#(\w)+/g
Searches for words that starts with#
The answer
/(?<!\w)#\w+/
given by Mark Bayers throws a warning like below onRegExr.com
websitethe warning can be fixed by changing it to
(?!\w)@\w+
by removing>
To accommodate different languages I have this (PCRE/PHP):
or
or to cycle through multiple scripts
\w
works great, but as far as I've seen is only for Latin script.Switch
Latin
forCyrillic
orPhoenician
in the above example.The above example does not work for 'RTL' scripts.