$re = '/^\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*))/m';
$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)
{';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php