Below is the JavaScript source code on which the php regex I am trying to apply.
<script>
function outerfunction () {
function abcd () {
return ('efgh', 1);
}
function efgh () {
return ('higk', 2);
}
}
</script>
I am trying to fetch all the inner function from the JavaScript code below with function name length having 4 chars, using preg_match_all()
with pattern /(function.[a-z]{4}.[(][)].*)}/s
. using this online tool phpliveregex.com
below is the output in 2nd array. but i need all the functions list as in individual array elements. currently it is comming inside single array element result.
Current output
array[1] => function abcd () {
return ('efgh', 1);
}
function efgh () {
return ('higk', 2);
}
Needed:
array[1] => function abcd () {
return ('efgh', 1);
}
array[2] => function efgh () {
return ('higk', 2);
}