[SOLVED] Failing to Replace article title using regex of (Hashtags, URLs). Am i doing it right? #1114
Answered
by
martinrotter
Starboy-Xo
asked this question in
Q&A
-
function filterMessage()
{
msg.title = msg.title.replace('#[a-z0-9_]+', ' ');
msg.title = msg.title.replace('[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&/=]*)', ' ');
return MessageObject.Accept;
} Please correct me if i am doing it wrong. |
Beta Was this translation helpful? Give feedback.
Answered by
martinrotter
Oct 6, 2023
Replies: 2 comments 2 replies
-
Hi brother. Will check. Do you have any sample feed where you apply this filter? |
Beta Was this translation helpful? Give feedback.
1 reply
-
OK, so first, in order to have your regexp syntax recognized, you have to use regex "/ /" syntax. Instead of "" use // as begin-end syntax of your regex, also add "g" modifier to replace all occurences. Like this: function filterMessage()
{
msg.title = msg.title.replace(/#[a-z0-9_]+/g, ' ');
return MessageObject.Accept;
} Similarly do the same for your second line which I believe also contains logical regex error. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Starboy-Xo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, so first, in order to have your regexp syntax recognized, you have to use regex "/ /" syntax. Instead of "" use // as begin-end syntax of your regex, also add "g" modifier to replace all occurences.
Like this:
Similarly do the same for your second line which I believe also contains logical regex error.