February 16, 2017, 1:58pm
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:
And the links are below
it works for me for both paths.
February 16, 2017, 7:10pm
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
February 16, 2017, 8:10pm
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.
May 19, 2017, 4:50pm
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.