php - Regex to replace spaces and brackets with underscore -


i have strings in following formats:

this string string (string)  string 

and want regex convert following:

this_is_a_string 

with no leading

i have following using preg_replace getting me of way:

preg_replace('/[^a-za-z]+/', '_', $string) 

however, converts last ) underscore not acceptable uses. trim off in separate function im wondering if possible single regex?

$result = preg_replace('~[^a-z]+([a-z]+)(?:[^a-z]+$)?~i', '_$1', $string); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -