Search code examples
regexnotepad++

Regular expression: non greedy search


In this kind of text:

['WRK', 'SOCCER', 'CHILD']
['FIN', 'TENNIS', 'CHILD']
['WRK', 'GOLF', 'CHILD']

I would like to extract:

    'SOCCER', 'CHILD'
    'TENNIS', 'CHILD'
    'GOLF', 'CHILD'

I tried:

    '.+'{1}?,\s'CHILD'

But gives me too much: the first term in single quotes should not be extracted. Thanks !


Solution

  • You may use the following find and replace, in regex mode:

    Find:    \['.*?',\s*(.*?)\]
    Replace: $1
    

    Demo

    This regex pattern matches the first singly quoted term, but does not capture it. The second term onwards is captured, up to, but not including, the closing square bracket. We then replace with just the first capture group.