nmeri17
February 16, 2017, 1:58pm
1
I need my regex to match both links below but unfortunately, it only matches the second one. I think the ?
should mean 0 or more chances of occuring but it doesn’t apply that way in my regex. The regex is as follows:
/\/([\w-]+)(\/[a-z]+\.([a-z]+))?$/gi
And the links are below
/login/file.css
/login
it works for me for both paths.
nmeri17
February 16, 2017, 7:10pm
3
Well, see for yourself in your browser dev console. It always outputs null (meaning no match found) for the first string.
/\/([\w-]+)(\/[a-z]+\.([a-z]+))?$/.test('/login/files.css') // true
/\/([\w-]+)(\/[a-z]+\.([a-z]+))?$/.test('/login') // true
'/login/files.css'.match(/\/([\w-]+)(\/[a-z]+\.([a-z]+))?$/gi) // ["/login/files.css"] (1) = $2
nmeri17
February 16, 2017, 8:10pm
5
Kindly explain how I can get it to work here https://jsbin.com/juxayoc/edit?js,console,output as desired i.e output the array of matches for both strings.
system
Closed
May 19, 2017, 4:50pm
7
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.