I would like a regex which
Grabs target
from This:
http://localhost/target or http://localhost/target/
B开发者_运维技巧ut NOT from This:
http://localhost/target/something/else
So If there is just one parameter after localhost and not more than one.
This should get you going:
^.*target/?$
'http://localhost/target/'.match( /^http:\/\/localhost\/(target)\/?$/ )
would match
- http://localhost/target
- http://localhost/target/
And not match
- http://localhost/target/f
You didnt specify whether the http matching was required, but if it isn't just remove that portion. This is a fairly primitive regex but should suffice.
/^http:\/\/localhost\/([^\/]+)\/?$/
Or if you can do a different delimiter like in Perl, to avoid LTS:
m|^http://localhost/([^/]+)/?$|
精彩评论