How to remove clasps in a regex?

Asked

Viewed 4,799 times

0

I’m using a regex to remove some characters, but as one of them is [ brackets] and I’m having problems with regex replace(/[.!'@,><|://\\;&*()_+=]/g, "");. How would it be to remove that character in this function?

3 answers

5


I just added at the beginning [ and ].

Stayed like this:

replace(/[\[\].!'@,><|://\\;&*()_+=]/g, "")

0

0

About regular expressions in general, for uses other than Javascript

Always walk with the Guide to Green Aurelius regular expressions (direct link to the list part). You can by closing the square bracket as a special character right after opening a list or a denied list; for example []abc], box the following characters:

  • ]
  • a
  • b
  • c

The clasp opener can be placed anywhere, it will not suffer special treatment.

I’m talking about the special positioning because there are regular expression processors that do not accept escape within lists or denied lists, so the regular expression [abc\]] is not treated in a manner equivalent to what I wrote earlier []abc].

As much as the focus of the question is Javascript, it is always good to have a general notion so as not to be surprised when using regular expressions in other places.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.