Skip to main content

RegEx in multiple files multi-line pattern

pcregrep -h -r --include=".*\.cs" -M "LogEvent\([\s\S]*?\)\;" .
  • -h: Exclude filenames
  • -r: recursive
  • --include: include file names that matches with the pattern
  • -M: multi-line mode
  • PATTERN: match all occurrence even if it is multi-line

Example: await LogEvent($"This is a test message that has embedded {property}");

pcregrep -h -r --include=".*\.cs" -o1 -M "LogEvent\(([\s\S]*?)\)\;" .
  • -o: shows only match, not the entire line. -o{n} shows only the {n}th group
  • Matches only: $"This is a test message that has embedded {property}"