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

    Join Date
    Aug 2013
    Location
    Carmichael, CA USA
    Posts
    3
    Rep Power
    0

    Regex novice question


    Sample text
    foo = "/test/abc/hello/f" //bar

    How do I match with everything prior to // with a named group
    and another named group2 with everything after and including //

    my full scenario is a bit more involved since I don't want to match blank lines, and I don't want to match lines that start with //some comment and I have some keywords that indicate not to match on line as well.

    My goal is to put a comma $1,$2 type of thing...when the line does not match keywords...

    So I was going down this path which handles not matching the lines with keywords, blanks, lines starting with a comment,but I am stumped on splitting the case where I want to split the stuff preceding a comment and the comment...
    (?=\S)^((?!.*(keyword1|keyword2)))(?!(^\s*//.*))

    TIA
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    225
    Rep Power
    41
    Post some test data that is exactly like the data you are working with.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    Carmichael, CA USA
    Posts
    3
    Rep Power
    0
    Originally Posted by spacebar208
    Post some test data that is exactly like the data you are working with.
    Sample

    foo = "/test/abc/hello/f" //bar
    //bar123
    if (1==2) //bing bong boom
    {
    a <> b

    Desired result (note semi colon inserted)
    foo = "/test/abc/hello/f"; //bar
    //bar123
    if (1==2) //bing bong boom
    {
    a <> b;

    fyi - I was able to do this with two passes... in the first regex, I find the //which is a comment and have various non capture criteria so I can insert the ; where appropriate for lines with comments that require a ;

    in the second regex, I simply append the ; for matching lines that don't have the comment now and since my non capture includes a ; it works. I'll post it tomorrow

    Nevertheless, I'm sure there is a better way to do it...and likely with a single expression....so I look forward to suggestions.

    djm
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    Carmichael, CA USA
    Posts
    3
    Rep Power
    0

    Other - regex novice question Draft solution


    Here is what I do in first pass...

    use to add semi to lines not containing keywords...sample
    ^((?!.*(\;|if|{)))(?!(^\s*//.*))(.*)(.*/{2,}.*)

    replacement
    $4;$5

    and then I do
    (?=[^\r\n\t])^((?!.*(\;|if|{|)))(?!(^\s*//.*))(.*)
    replacement
    $4;

    I'm still interested in feed back on whether this could be done with one expression.

    djm

    Originally Posted by trinco
    Sample text
    foo = "/test/abc/hello/f" //bar

    How do I match with everything prior to // with a named group
    and another named group2 with everything after and including //

    my full scenario is a bit more involved since I don't want to match blank lines, and I don't want to match lines that start with //some comment and I have some keywords that indicate not to match on line as well.

    My goal is to put a comma $1,$2 type of thing...when the line does not match keywords...

    So I was going down this path which handles not matching the lines with keywords, blanks, lines starting with a comment,but I am stumped on splitting the case where I want to split the stuff preceding a comment and the comment...
    (?=\S)^((?!.*(keyword1|keyword2)))(?!(^\s*//.*))

    TIA

IMN logo majestic logo threadwatch logo seochat tools logo