英文:
Why .includes on string doesn't detect lower case letters?
问题
I wrote this to detect if the url contain this particular keyword i.e. recordId but if url contains it in lower i.e. recordid then it doesn't detect.
如何使它们都被检测到,因为数据可以包含recordid或recordId。
if(url && url.includes("recordId") && url.includes("rt")){
this._geRecordId(url);
}
private async geRecordId(url){
const linkedId = this._getURLValue('recordId', url);
if(!linkedId){
return;
}
}
private _getURLValue(name, url) {
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");
var regexS = "[\\;]"+name+"=([^;]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
return results == null ? null : results[1];
}
I tried changing regex.
英文:
I wrote this to detect if the url contain this particular keyword i.e. recordId but if url contains it in lower i.e. recordid then it doesn't detect.
How do I make them detect both because data can have both recordid or recordId.
if(url && url.includes("recordId") && url.includes("rt")){
this._geRecordId(url);
}
private async geRecordId(url){
const linkedId = this._getURLValue('recordId' , url);
if(!linkedId){
return;
}
private _getURLValue( name, url ) {
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\;]"+name+"=([^;]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
return results == null ? null : results[1];
}
I tried changing regex
答案1
得分: 1
你可以使用带有 i 标志的正则表达式,这样它将匹配大写和小写字母。
/recordId/i.test(url)
英文:
You can write a regex with the i flag, so that it will match both uppercase and lowercase letters.
/recordId/i.test(url)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论