Regular Expression: What is the wrong with this code ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abdoelmasry
    New Member
    • Oct 2006
    • 104

    Regular Expression: What is the wrong with this code ?

    What is the wrong with this code ?

    it always returns zero matches.

    I think it should return two matches,

    I need to read how may tags like this pattern

    Code:
    <!== any thing ==!>
    Code:
    $string = "<!==Abdo==!><!==Ahmed==!>";
    print_r(preg_match_all("/<\!==*==\!>/", $string));
    if anybody can help.

    Thank you
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The asterisk (*) character tells it to take the preceding character/group and look for 0 to infinite matches. So in this case, you are saying you want 0 to infinite equal sign symbols (=). Asterisk does not mean any number of character.

    The expression you want is <!==[^<]*==!>. What you want is for it to match any number of characters that is not a less than symbol (<). Therefore, [^<] matches a character that is not a less than symbol. And the asterisk after it tells it to match any number of characters that is not a less than symbol.

    Comment

    • abdoelmasry
      New Member
      • Oct 2006
      • 104

      #3
      Thank you Pro Very good (y)

      Comment

      Working...