#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    158
    Rep Power
    98

    Match lines which occur after specific line


    I have a config file with a user editable section - the end of the file. I'm trying to write a regex that replaces these lines, but only after we've matched the config section.

    This regex matches the lines I want to match:

    [code=regex]
    (^(paramone optionone |paramtwo optiontwo )[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(?=\n)?$)+
    [/code]

    This regex is the lookbehind I can use to match the first line only:
    [code=regex]
    (?<=###CONFIG USER SECTION###\n)
    [/code]

    Is there a way I can match all lines meeting the criteria of the first regex only after having matched the regex in the regex2 lookbehind?


    [edit]

    In case I'm not 100% clear on this:

    If I have a file with the following lines:

    paramone optionone 127.0.0.1
    paramtwo optiontwo 127.0.0.1
    ###CONFIG USER SECTION###
    paramone optionone 1.2.3.4
    paramtwo optiontwo 1.2.3.4
    paramone optionone 5.6.7.8
    paramtwo optiontwo 5.6.7.8
    paramone optionone 127.0.0.1
    paramtwo optiontwo 127.0.0.1

    I want to be able to match either:
    paramone optionone 1.2.3.4
    paramtwo optiontwo 1.2.3.4

    or

    paramone optionone 5.6.7.8
    paramtwo optiontwo 5.6.7.8

    or the second instance, and only the second, of:

    paramone optionone 127.0.0.1
    paramtwo optiontwo 127.0.0.1
    Last edited by WrinkledCheese; August 7th, 2013 at 01:53 PM.

IMN logo majestic logo threadwatch logo seochat tools logo