Friends, I'm rushing towards deadline and I think that makes me do childish mistakes. Here I have validation that requires regex and each time I input valid expression preg_match returns false. It is long now I'm trying to spot error but I cannot! I have googled and AFAICS, things seems alright please help me spot the error. Thanks, Stefano

<?php
    
    $string = "37961/T.08";//valid ID, it is supposed to match
    $regex = '/^[0-9]{5,}/[a-zA-Z]\.[0-9]{2,}/';
    if (preg_match($regex, $string)) {
        echo matched expression!';
    }  else {
        echo 'unmatched expression pattern';//comes here instead of valid regex!
    }
    
    ?>
$regex = '/^[0-9]{5,}\/[a-zA-Z]\.[0-9]{2,}$/';
$regex = '/^[0-9]{5,}\/[a-zA-Z]\.[0-9]{2,}$/';

Thanks a lot, someone answered here. Can I know why is / escaped? I thought only \ is escaped :-O
Also doe these two differ as far as regex is concerned?

$regex = '/^[0-9]{5,}\/[a-zA-Z]\.[0-9]{2,}$/';
$regex = "/^[0-9]{5,}\/[a-zA-Z]\.[0-9]{2,}$/";

The / is escaped because it signifies the end (or start) of the pattern.
Only pattern modifiers can follow after that.

And there is no difference between those two.

The / is escaped because it signifies the end (or start) of the pattern.
Only pattern modifiers can follow after that.

And there is no difference between those two.

Thanks. Issue solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.