Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    24
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Regular Expression /bb|[^b]{2}/

    http://xrg.es/?631614439

    Having an issue trying to match.

    The string is simple:
    PHP Code:
    $options[one][two][three
    I need to match "options", "one", "two", and "three", but my regular expression only matches "three".

    Is there a simple way to pull all that information?

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Don't think you'll be able to do this with just one regex. You'll need to match $options then the [...][...][...] capturing them all, then do a preg_match_all on those

    PHP Code:
    $text '$options[one][two][three]';
    preg_match('/\$(\w+)((\[\w+\])+)/'$text$out);
    preg_match_all('/\[\K[^\]]+/'$out[2], $out2);
    $var_name $out[1];
    $arrays $out2[0]; 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •