const regex = new RegExp('^\\s*((public|private|protected)? *(static)? *(void|int|String|boolean|float|double) +[a-zA-Z_](\\w)* *[\\(] *(((int|String|boolean|float|double) +[a-zA-Z_](\\w)*))* *( *, *int +[a-zA-Z_](\\w)* *| *, *String +[a-zA-Z_](\\w)* *| *, *boolean +[a-zA-Z_](\\w)* *| *, *float +[a-zA-Z_](\\w)* *| *, *double +[a-zA-Z_](\\w)* *|\\))+\\s*[{]\\s*|( *public +static +void +main *\\( *String *(\\[\\])? * args *(\\[\\])? *\\)\\s*[{]\\s*))', 'gm')
const str = `public static void salud(String hola,boolean siu) {
void ultimo(int hola){
public void saludos(){
void numeros(String cola, int hola, String si){
public static void main(String[] args){
protected String idnombre (int n){
protected void prueba(String a,int b){
public static void main(String[] args[]){
public static void main(String args[]){
void hola(){}
void hola(){
public void main(String id)
{
public void hola ( int c)
{`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions