preg_match with brackets

Discussion in 'PHP' started by Silver89, Jan 10, 2010.

  1. #1
    If I'm trying to find the content within the brackets as follows using preg_match:

    Name (SubName)

    I've Tried:

    
    (([a-zA-Z]+))
    
    Code (markup):
    but it doesn't seem to work?
     
    Silver89, Jan 10, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Escape it ) -> \) and ( -> \(

    <?php
    
    $var = "Name (SubName)";
    
    if(preg_match("#(\([a-zA-Z]+\))#", $var, $matches)) {
    
    print_r($matches);
    
    }
    
    ?>
    PHP:
     
    danx10, Jan 10, 2010 IP
    Silver89 likes this.