anmml
anmml

Reputation: 263

Delete annoying hashtags from a string using javascript regax

How to delete the whole line if it all is hashtags using JavaScript regex, for example:

text #string
#hashtag1 #hashtag2 #hashtag3

it will be:

text #string

Thank you for all answers

Upvotes: 0

Views: 780

Answers (2)

SergeyS
SergeyS

Reputation: 3553

What about this?

text.replace(/^(\s*#\w+\s*)+$/gm, "")

Notice m flag there, it means 'multiline'.

Upvotes: 0

forehead_sniffer
forehead_sniffer

Reputation: 91

I guess this will help

string.replace(/\#\S+/g,'');

UPD: I got you. try this:

string.replace(/(\n|^)(\#\S+\s+|\#\S+)+(\n|$)/g,'');

Upvotes: 1

Related Questions