Solved

Easy Regular Expressions Question

Posted on 2004-08-07
2
262 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:blacksix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Assisted Solution

by:ldbkutty
ldbkutty earned 25 total points
ID: 11743004
<?php
$myString = "032|Robin|Scace|0|No Schedule|";
echo substr_count($myString, "|"); // prints out 5
?>
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 50 total points
ID: 11743021
Hi

You mean something like

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

Regards,
Zyloch
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question