Skip to main content
edited body
Source Link
iruvar
  • 17k
  • 8
  • 51
  • 81

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!.*donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (groupmatch); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!.*donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (group); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!.*donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (match); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^

added 2 characters in body
Source Link
iruvar
  • 17k
  • 8
  • 51
  • 81

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!donotmatch.*donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (group); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (group); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!.*donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (group); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^

Source Link
iruvar
  • 17k
  • 8
  • 51
  • 81

Assuming I've understood your need correctly, if your match command takes the form pcregrep -o1 '(match)', the corresponding regex that would report a match only if another string is not matched is pcregrep -o1 '^(?!donotmatch).*(match)'. Look up negative lookahead expressions in the PCRE documentation. Also notice the .* in front of the (group); this is needed due the anchoring of the negative looking ahead expression to the start of the line via the ^