Hi i am having trouble to replace five “|||||” to one “|”.
var ss = "123|||||456|||||789|||||";
var ww = ss.replace(/[|||||]\W/g, "|");
The output i get is
123|||456|||789|||
What are the correct RegEx i should write??
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do the following:
As mentioned in the comments, the
[]defines a character class and matches any of the characters defined in it. for example[a-z]will match the lowercase alphabet.However since you only need to match the pipe (
|) character, you can remove the brackets and escape it like so:It needs to be escaped by a
\because the pipe is a special character in java script.The curly notation
{5}after the pipe defines how many of ‘the previous’ you want to match.