php - Regex to replace character with character itself and hyphen -


i need replace camelcase characters camel case character , -.

what have got string those:

albert-weisgerber-allee 35 bruninieku iela 50-10 

those strings going through regex seperate number street:

$data = preg_replace("/[^ \w]+/", '', $data); $pcre = '\a\s*(.*?)\s*\x2f?(\pn+\s*[a-za-z]?(?:\s*[-\x2f\pp]\s*\pn+\s*[a-za-z]?)*)\s*\z/ux'; preg_match($pcre, $data, $h); 

now, have 2 problems.

  1. i'm bad @ regex.

  2. above regex cuts every - streets name, , there lot of names in germany , europe.

actually quite easy adjust regex not cut hyphens, want learn how regex works , decided try find regex replaces every camel case letter in string

- & matched camel case letter 

except first uppercase letter appearance.

i've managed find regex shows me places need paste hyphen so:

.[a-z]{1}/ug      

https://regex101.com/r/qi2ia9/1

but how on earth replace string:

albertweisgerberallee  

that becomes

albert-weisgerber-allee 

to insert dashes before caps use regex:

$string="albertweisgerberallee"; $string=preg_replace("/([a-z])([a-z])/", "\\1-\\2", $string); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -