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

    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Need to skip multiline charachters and single line characters


    Hello,
    Can any body tell me i need to skip the whole text which is commented (whether multiline or single line) and match the next text with simple regexs.

    e.g

    /*
    This is sample text_1 in multi line comments
    This is sample text_2 in multi line comments
    */
    Text after comments

    Now i only want to match string "Text after comments" and regex whould skip whole commented text and only give me output as "Text after comments"

    Regards
    Muhammad Usman Khalil
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    In PHP:
    PHP Code:
    $string "/*
    This is sample text_1 in multi line comments
    This is sample text_2 in multi line comments
    */
    Text after comments"
    ;
    //php cannot do multi-character negation:
    $string str_replace("*/"""$string);
    preg_match("#/\*[^]+\s*([^\n]+)#m"$string$matches);
    echo 
    "Text after commends is: {$matches[1]}"
    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo