Search code examples
regexmultiline

Find line + 1 line after it


How to find line + one line after that?

Eg I have the lines

123123
some text
546454
some text
354543
some text
465466
some text
123123
some text

So i know how to find 123123 (^123123) and other but how get +1 line with text 'some text'

result shoud be

123123
some text
123123
some text

Update

I forgot to say, after text can be other text 123123 is start of line

123123 text text text text text
some text

Sorry


Solution

  • You can use a new line between your pattern and related regex for next line :

    /123123\n[^\d]+/g
    

    Demo https://regex101.com/r/zA2cU6/1

    Note that [^\d]+ will match any combination of characters which doesn't contains digit.(you can change it based on your need)

    Update:

    If you want to match the text after your pattern you just can add .* after it :

    123123.*\n[^\d]+
    

    Demo : https://regex101.com/r/zA2cU6/2