Search code examples
regexexpressionlookbehind

Match the next word after a regex expression


I want to match a word after a regex expression.

For e.g I came up with a regex expression to match date and time - <Apr 11, 2017 2:35:53 AM SGT>

<(Jan|Feb|Mar|Apr|May|June|July|Aug|Sept|Oct|Nov|Dec)\s(\d\d?).+?(\d\d\d\d)\s\b((1[0-2]|0?[1-9]):([0-5][0-9]):([0-5][0-9]) ([AaPp][Mm])\sSGT)>

Can see that it works here

I want to take it further to match the word after this regex.

Apr 12, 2017, 10:56:22 AM   Hello   #### <Apr 12, 2017 2:27:08 AM SGT> <Info> 

So it should only match the word <Info> but it highlighted

 12, 2017, 10:56:22 AM Hello #### <Apr 12, 2017 2:27:08 AM SGT> <Info>

My regex expression

Appreciate every help!


Solution

  • If you just want to grab <info>, just extand your regex to match the next word:

    <(?:Jan|Feb|Mar|Apr|May|June|July|Aug|Sept|Oct|Nov|Dec)\s\d\d?.+?\d\d\d\d\s\b(?:1[0-2]|0?[1-9]):[0-5][0-9]:[0-5][0-9]\s[AaPp][Mm]\sSGT>\s(<\w+>)
    

    Example.