Using JavaScript and I want to replace any text between @anytext@ with some text. I want to make it generic so I am thinking to make use of regular expression. How do I do it?
Example:replace(‘@hello@’,’Hi’)
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.
Try this:
This will remove any sequences of
@ … @globally withHi.Edit Some explanation:
/…/is the regular expression literal syntax in JavaScript@[^@]+@describes any sequence of a literal@, followed by one or more (+quantifier) characters that is not a@(negated charcater class[^@]), followed by a literal@gflag in/…/gallows global matches; otherwise only the first match would be replaced