2
Guys, I have a question here and I don’t know if it’s possible to do what I want (I think so). The question is, I have a switch(link) and follow example of cases (example link):
marry "http://www.link.com.br/example/": break;
marry "http://www.link.com.br/exemplo/index.html": break;
marry "http://link.com.br/example/": break;
marry "http://link.com.br/exemplo/index.html": break;
and I need to do this with several links. Is there any way, using Regex, to check in a case whether or not the url has this www. and the /index.html not to create several unnecessary lines? (Note: if applicable, it can be with if/Else).
I don’t understand what you want to do... you want to detect
www.
in string? and do what if you have?– Sergio
Yes, I want to do something that, whether there is or is not www. or /index.html it performs such a function. This was an example code, in fact it will perform a function in each case...
– Igor
And you need regex for that? Can you do it with
if (url.indexOf('www.') != -1) fazer algo...
– Sergio
I would like the regex simply not to have to do this, in which case I would have to do several checks. What I really wanted was "http://(if you have or don’t have www.)link.com.br/example/(if you have.
– Igor
The url always starts with
http://
? The dominion is always the same?– Sergio
Yes, exactly.
– Igor
Forehead like this
if (/http:\/\/(www\.)?.*(index\.html)?/.test("http://link.com.br/exemplo/")) fazer algo...
– Sergio