TIMEX TIMEX - 3 months ago 8
Javascript Question

How can I make all @mentions lowercase?

Given a string,

@Jonathan and @Alex are going to the movies.


The function should return a string equal to:

@jonathan and @alex are going to the movies.


How can I process this string so that all @mentions are lowercase?

Answer

Try this:

console.log("@Jonathan and @Alex are going to the movies.".replace(/(^|\s)@\w+/g, (match) => match.toLowerCase()));

Comments