JavaScript / ECMAScript

Hashtag in JS

Match hashtags (# followed by word characters) in social media posts, including accented Latin characters.

Try it in the JS tester →

Pattern

regexJS
#([\w\u00C0-\u024F]+)   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("#([\\w\\u00C0-\\u024F]+)", "g");
const input = "Loving #JavaScript and #regex!";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

# matches the literal hash. The capturing group ([\w\u00C0-\u024F]+) matches one or more word characters (letters, digits, underscore) plus Latin Extended Unicode range for accented characters like #café or #naïve.

Examples

Input

Loving #JavaScript and #regex!

Matches

  • #JavaScript
  • #regex

Input

Post tagged #café and #naïve

Matches

  • #café
  • #naïve

Input

No hashtags here

No match

Same pattern, other engines

← Back to Hashtag overview (all engines)