The following code snippet shows you how to use regular expression to split a string with no spaces, only capital letters. The result is stored into an array that preg_match_all created. Note that $matches is a multi-dimensional array created by preg_match_all.
<pre>
<?
$exp = "/[A-Z]([^[A-Z]+]*)?/";
$sub = "ThisIsATestString";
preg_match_all($exp,$sub,$matches);
print_r($matches[0]);
?>
</pre>
<?
$exp = "/[A-Z]([^[A-Z]+]*)?/";
$sub = "ThisIsATestString";
preg_match_all($exp,$sub,$matches);
print_r($matches[0]);
?>
</pre>
If you want to split the string, you could write the regular expression with a php preg_split
<pre>
<?
$exp = "/(?=[A-Z])/";
$sub = "ThisIsATest";
$array = preg_split($exp,$sub);
print_r($array);
?>
</pre>
<?
$exp = "/(?=[A-Z])/";
$sub = "ThisIsATest";
$array = preg_split($exp,$sub);
print_r($array);
?>
</pre>
0 comments ↓
If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.
DCE Related Posts
Read Full Article...
Read Full Article...
This code shows how to strip http, www, or any suffixes like .com or .co.uk etc. Read Full Article...
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment