I want to get the string after =" and before " eg - unSelAll('FBtest11_6',this.value,this.id)
some times the =" " might be =''
eg - onclick ='unSelAll("FBtest11_6",this.value,this.id)'
I want the string starting from function name only
I want to get the string after =" and before " eg - unSelAll('FBtest11_6',this.value,this.id)
some times the =" " might be =''
eg - onclick ='unSelAll("FBtest11_6",this.value,this.id)'
I want the string starting from function name only
This regex will do the following:
onclick =
and return the associated valueonclick
and it's associated =
Regex
(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\s*\Konclick\s*=(['"]?)(.*?)\1(?:\s|$)
Capture Groups
onclick
string includeing the value and surrounding quotesonclick
value not including any quotesSample Text
Note the difficult edge case in the second line
onclick ='unSelAll("FBtest11_6",this.value,this.id)'
onmouseover=" onclick ='This is not the droid you are looking for' " onclick ="find me instead"
Sample Matches
[0][0] = onclick ='unSelAll("FBtest11_6",this.value,this.id)'
[0][1] = '
[0][2] = unSelAll("FBtest11_6",this.value,this.id)
[1][0] = onclick ="find me instead"
[1][1] = "
[1][2] = find me instead
Live Example
https://regex101.com/r/yU8eL1/2
NODE EXPLANATION
----------------------------------------------------------------------
(?: group, but do not capture (0 or more times
(matching the least amount possible)):
----------------------------------------------------------------------
[^>=] any character except: '>', '='
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
=' '=\''
----------------------------------------------------------------------
[^']* any character except: ''' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
' '\''
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
=" '="'
----------------------------------------------------------------------
[^"]* any character except: '"' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
= '='
----------------------------------------------------------------------
[^'"] any character except: ''', '"'
----------------------------------------------------------------------
[^\s>]* any character except: whitespace (\n,
\r, \t, \f, and " "), '>' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
)*? end of grouping
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\K 'K'
----------------------------------------------------------------------
onclick 'onclick'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
= '='
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
['"]? any character of: ''', '"' (optional
(matching the most amount possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
\1 what was matched by capture \1
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
$ before an optional \n, and the end of
the string
----------------------------------------------------------------------
) end of grouping