Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript case-insensitive match for part of a string only

I have the following regex -

bannerHtml.match(/href\s*=\s*[\"']{clickurl}(.*)[\"']/);

which matches the following -
href = "{clickurl}

Now, I want the matching of href only to be case-insensitive, but not the entire string. I checked adding i pattern modifier, but it seems to be used for the entire string always -

bannerHtml.match(/href\s*=\s*[\"']{clickurl}(.*)[\"']/i); 

Further details I want all of the following to match -
hREF = "{clickurl}
href = "{clickurl}
HREF = "{clickurl}

But, capital case clickurl part should not match -
href = "{CLICKURL}

like image 358
Sandeepan Nath Avatar asked Feb 17 '23 11:02

Sandeepan Nath


1 Answers

You can use:

/[hH][rR][eE][fF]\s*=\s*[\"']{clickurl}(.*)[\"']/

The part that changed is: [hH][rR][eE][fF], which means:

Match h or H, followed by r or R, followed by e or E, and followed by f or F.


If you want to make it generic, you can create a helper function that will receive a text string like abc and will return [aA][bB][cC]. It should be pretty straightforward.

like image 126
Oscar Mederos Avatar answered Feb 20 '23 02:02

Oscar Mederos