mirandalol
mirandalol

Reputation: 465

Regex to match this

I'm trying to capture from PHPUnit output the file path and the error line with a condition.

This is my output and non-working (obviously:) pattern:

/path/includes/exception.php:7
/path/things-i-care-about/es/somefile.php:132
/path/things-i-care-about/es/somefile.php:121
/path/things-i-care-about/es/somefile.php:54
/path/things-i-care-about/es/somefile.php:60
/path/things-i-care-about/es/somefile.php:41
/path/things-i-care-about/es/somefile.php:47
/path/things-i-care-about/testfile.php:26

Pattern: /((?!exception).*.php):(\d.*)/gs

What I tried is negating any line that has "exception" in it, but my regex didn't quite work.

What am I doing wrong?

Upvotes: 1

Views: 65

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

You can try this pattern:

^(?:[^e\n]+|\Be|\be(?!xception\b))+\.php:\d+$

or this pattern, if you don't need to check a specific line format:

^(?>[^e\n]++|\Be|\be(?!xception\b))+$

Notice: If you need to select all consecutive lines in one block, you just need to remove \n from the character classes.

Upvotes: 2

Related Questions