Good-bye Good-bye - 1 year ago 119
PHP Question

Split camelCase word into words with php preg_match (Regular Expression)

How would I go about splitting the word:


into an array so that I can get:

one Two Three Four


I tired this but it just gives the whole word

$words = preg_match("/[a-zA-Z]*(?:[a-z][a-zA-Z]*[A-Z]|[A-Z][a-zA-Z]*[a-z])[a-zA-Z]*\b/", $string, $matches)`;

Answer Source

You can also use preg_match_all as:


See it


(        - Start of capturing parenthesis.
 (?:     - Start of non-capturing parenthesis.
  ^      - Start anchor.
  |      - Alternation.
  [A-Z]  - Any one capital letter.
 )       - End of non-capturing parenthesis.
 [a-z]+  - one ore more lowercase letter.
)        - End of capturing parenthesis.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download