regex match after word

12,663

Instead of a positive lookbehind that does not allow unknown width patterns, you may use a match reset operator \K:

^BEGIN_TAG:\W?\K.*

See the regex demo

Details:

  • ^ - in Sublime, start of a line
  • BEGIN_TAG: - a string of literal chars
  • \W? - 1 or 0 non-word chars
  • \K - the match reset operator that discards all text matched so far
  • .* - any 0+ chars other than linebreak characters (the rest of the line) that are the only chars that will be kept in the matched text.
Share:
12,663
user254340
Author by

user254340

FPGA VHDL engineer. Closeted software engineer.

Updated on June 14, 2022

Comments

  • user254340
    user254340 almost 2 years

    I would like to know how to capture text only if the beginning of a line matching a certain string... but i dont want to capture the begining string...

    for example if i have the text:

    BEGIN_TAG: Text To Capture

    WRONG_TAG: Text Not to Capture

    i want to capture:

    Text To Capture

    From the line that begin with BEGIN_TAG: not the line that begin with WRONG_TAG:

    I know the how to select the line that begin with the desired text: ^BEGIN_TAG:\W?(.*)

    but this selects the text "BEGIN_TAG:"... i dont want this only want the text after "BEGIN_TAG"

    I am using PCRE regex