我有一个正则表达式
// Look for /en/ or /en-US/ or /en_US/ on the URL
var matches = req.url.match( /^\/([a-zA-Z]{2,3}([-_][a-zA-Z]{2})?)(\/|$)/ );
现在,使用上面的正则表达式将会导致URL出现问题,例如:
css/bootstrap.css
或
js/jquery.js
因为我的正则表达式是从A-Z或a-z中剥离2-3个字符
我的问题是,我如何添加到这个正则表达式中,而不用
js、img、css或ext
而不会影响原来的版本。
我对正则表达式不是很在行:
我正试着从一个页面中得到一个链接
url: '和',
我尝试过通过google找到几种不同的解决方案,但我得到的最接近的解决方案是
function pregmatch() {
var re = new RegExp("url: '(.*)',", "g"),// the regex
txt = 'some text'; // the text on page to be replaced by url
newtxt = txt.replace(txt,re); // replace
在使用匹配约束时,如何转义正则表达式中的正斜杠?这是我尝试过的:
constraints {
url (
matches: "^http://www.google.com/$"
)
}
错误:solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}"
constraints {
url (
matches: "^http:\/\/www.google.com\/$