-1

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

heaxyh
  • 573
  • 6
  • 20
tester
  • 11
  • 4
  • How about `url.toLowerCase().includes("recordid")` ? – Shri Hari L Apr 13 '23 at 06:54
  • or includes("recordid".toLowerCase()) ? – tester Apr 13 '23 at 07:04
  • 3
    Because it's meant to be: "The includes() method is case sensitive. (...) You can work around this constraint by transforming both the original string and the search string to all lowercase". From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes). – Sangbok Lee Apr 13 '23 at 07:10

1 Answers1

1

You can write a regex with the i flag, so that it will match both uppercase and lowercase letters.

/recordId/i.test(url)

shalomOlam
  • 19
  • 6