S Joshi
S Joshi

Reputation: 3

Regex code to search multiline string in a text file

I am trying to build a regex to find below multiline text in Notepad++ using

(*ANYCRLF)(SPIDs at the head of blocking chains)\n(spid)\n.\n[1-9]

But it only works till SPID. What expressions help it to find 20 characters of - and in the next line numbers (1-9). The text wasn't showing up properly.

The spid word is a constant and case sensitive. Only numerical values would be different but in the range of 1 to 9.

Matching text:

SPIDs at the head of blocking chains
spid                
-(dash) 20 times
               13257

Upvotes: 0

Views: 481

Answers (1)

The fourth bird
The fourth bird

Reputation: 163632

In your regex (*ANYCRLF)(SPIDs at the head of blocking chains)\n(spid)\n.\n[1-9] you are matching \n.\n which will match a newline followed by any character and a newline. Instead of matching any character, you could match a dash 20 times -{20}.

You could update the last \n to \s* to match zero or more times a whitespace character and at the end match one or more times [1-9]+

(*ANYCRLF)(SPIDs at the head of blocking chains)\n(spid)\n-{20}\s+[1-9]+

Or instead of using (*ANYCRLF) and \n you might use \s:

\s*(SPIDs at the head of blocking chains)\s*(spid)\s*-{20}\s*[1-9]+

You use capturing groups () for (SPIDs at the head of blocking chains) and (spid) but if you only want to match the values you can omit the parenthesis.

Upvotes: 1

Related Questions