Easy Regular Expressions Question

Hi everyone - This shouldn't be too bad at all, but I know it would take me a while to figure it out so I'd appreciate the help.  I've got a variable containing 1 a string that looks something like this:

032|Robin|Scace|0|No Schedule|

All I want to do is test this string and make sure there are exactly 5 pipes in it, no more no less.

Thanks in advance!
LVL 5
blacksixAsked:
Who is Participating?
 
ZylochConnect With a Mentor Commented:
Hi

You mean something like

if (preg_match_all("/|{5}",$yourString)) {
   echo("There are exactly 5 pipes in the string.");
}

Regards,
Zyloch
0
 
ldbkuttyConnect With a Mentor Commented:
<?php
$myString = "032|Robin|Scace|0|No Schedule|";
echo substr_count($myString, "|"); // prints out 5
?>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.