there are strings:
$string1 = "text3256";
$string2 = "23PT";
I would like to somehow check if the word belongs to pattern "NumberText" or "TextNumber" for the purpose of splitting word into 2 parts: a "Number" and a "Text"
In the example above - words shall be divided into following:
"text3256" -> "text" and "3256"
"23PT" -> "23" and "PT"
Is it possible to create such Regex pattern? (words such as "text32text" or "44fd675" shall not be divided)..
I can most certainly create a hardcode solution using the "each character iteration" approach and checking if next character is a letter or a numeric.. that's a hardcore, so, I wondered if someone could help me out with a better, easier solution?
You can use:
'/^(?:(?:([a-z]+)(\d+))|(?:(\d+)([a-z]+)))$/i'
I prefer using boundaries:
/\b((\d+)([a-z]+)|([a-z]+)(\d+))\b/i
Example: http://codepad.viper-7.com/8muVjE