Remove WWW and HTTP / HTTPS with regular expression

Asked

Viewed 222 times

0

Hello, I am making a script that inserts values inside a finance system, but when you insert with http 'www' 'https' it is an error and I have to remove in hand. So I want to put a regular expression that removes these values from the url before sending. The script is already sending, so I would like help to form the regular expression.

  • 1

    This depends on the language in use, each has its own way of doing the replace. For this it is only necessary to give a match on "www|https? ' and subtlety for nothing

  • What backend language?

  • i to creating the script with JS. So I use . replace(***)

1 answer

0


To remove www, http and https you need to use replace as follows:

string.replace( /www|https?/ , '');

The ? indicates that the s is optional can exist or not and if there is will be replaced.

The | is the conditional or

  • His answer supplied the need, but I gave an improved to cover more options of sites because the user always surprises, was like this: . replace(/h? t? t? p? s?:? //w? w???| www./ , '')

  • 2

    @Leticiafatima, if the idea is to remove the protocol and "www", it is worth taking a look at this one here: https://regex101.com/r/Bj4RwO/2

  • Carlosn, this is perfect!!

Browser other questions tagged

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