How Can I test (true or false) on this regex statement: $pattern = '/\/ /';

Posted on 2009-04-02
Last Modified: 2012-05-06
How Can I test (true or false) on this regex statement:
$pattern = '/\/ /';

So, I want to return TRUE if there's more than two slashes in a row.
Question by:level9wizard
LVL 13

Accepted Solution

marchent earned 350 total points
ID: 24053533

$str = "Hello // world ////, how are/// you?";

## if string has 2 or more / on it

if( preg_match('|/{2,}|', $str) ){

    return true;


Open in new window

LVL 10

Assisted Solution

aboo_s earned 50 total points
ID: 24053571
I'm not sure I got it, but anyway here you go:



            echo 'true';

                              else echo 'false' ;

Assisted Solution

prokvk earned 50 total points
ID: 24053761
Here you go:



        $s = 'asdad // dasfsd / dsdfsdfs';


        if (ereg('([/]{3,})',$s))


            echo 'ok';




            echo 'NOT ok';




Open in new window

LVL 15

Assisted Solution

fsze88 earned 50 total points
ID: 24056344
$str = 'Hello // world ////, how are/// you?';

$pattern = '/\/+/';
$replacement = '/';

        if (ereg('\/{2,}',$str))
            echo 'yes, more than one / there';
            echo 'no double /';
echo preg_replace($pattern, $replacement, $str);
//echo str_replace($pattern, $replacement, $str);


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now