PHP Regex matching any character

Discussion in 'PHP' started by Dman91, Dec 25, 2008.

  1. #1
    Alright, since I wanted to test my skills in regex, I tried to get the contents between <textarea></textarea> for some reason it doesn't work.
    Since the file is very big, I have uploaded it on pastebin.
    Would appreciate any help.

    Link to php file - http://pastebin.com/m2e41cd54
     
    Dman91, Dec 25, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Adding the non-greedy modifier (?) to your first sub-match (.*) fixes it.

    preg_match('#<textarea(.*?)>(.*)</textarea>#s', $test, $match);
    PHP:
    Alternatively, you could make the entire match non-greedy by using the U pattern modifier ending.

    preg_match('#<textarea(.*?)>(.*)</textarea>#Us', $test, $match);
    PHP:
    Try reading this to learn more about non-greedy modifiers
     
    zerxer, Dec 26, 2008 IP