Question

I'm trying to find all words with a hash in front if they are placed after the end of the sentence. (These ones: #Example #FOO #hello_world #foo-bar #2012 #special-äüöå #russia-Русский #arabic-العربية)

This is the RegExp:

var regex:RegExp = /#[\w\-]+?(?= #|$)/g;

This is the text:

Lorem ipsum dolor #sit_amet, consetetur sadipscing, sed #diamnonumy eirmod tempor #invidunt ut. #Example #FOO #hello_world #foo-bar #2012 #special-äüöå #russia-Русский #arabic-العربية

It works except if special characters are included such as in #special-äüöå #russia-Русский #arabic-العربية

How to extend the RegExp to recognize special characters and non latin languages?

Thanks. Uli

Was it helpful?

Solution

Instead of using the character class [\w\-], you should use [^#].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top