0

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!
    }
    
    ?>
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
0
$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,}$/";
0

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.

0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.