Thread: [silverado]

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Question [silverado]


    Hello,

    I try to cut out the text inside brackets both '[{' and '['. With pattern I have "(\[{|\[).+(\}]|\])" I can cut out only text in brackets.
    Does anybody know how to cuto out word SILVERADO out of the [SILVERADO]?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    29
    Rep Power
    0
    Please try:

    Code:
    (?<=(\[)|(\{)).+?(?=(?(1)\]|\}))
    Lookahead and lookbehind is used to cut the word inside brackets, not including the brackets themselves. ?(1) condition checks what kind of opening bracket have you used, { or [, and matches the appropriate closing bracket. The non-greedy repetition .+? avoids eating everything until the last bracket in the text; only the text inside one bracket is consumed.

    Code:
    <?php
    
    $a = '{silverado} [silverado]';
    
    $a = preg_replace( '/(?<=(\[)|(\{)).+?(?=(?(1)\]|\}))/', '', $a );
    
    echo $a;
    
    ?>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0
    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo