Ronaldo Killergod Ronaldo Killergod - 3 months ago 12
Javascript Question

Best way of extracting substring from a string by regex - javascript (string value below)

var stringname="function func() {alert('testing savecallback2');}"


This is the string value I was having hard time extracting.
I want to extract "func()" or any name that appends with "()".

Please help me up.

Answer

you want like this?

var arr = "function func() {alert('testing savecallback2');}".match(/\s([A-Za-z0-9]+\(\))\s/);
console.log(arr[1])