Search code examples
regexnotepad++

Choosing Specific Regex Patterns While Excluding Others


I want to bookmark following regex lines in notepad++:

(?<!\d)0*\K(?:\d{1,3}(?:,\d{3})+|(?!0+(?!\d))\d{1,4})(?!\d)

but I don't like following regex lines select with above regex too:

\d{4}Q[1-4]

How can I do this?

I tried following regular expressions but not working:

(?<!\d)0*\K(?:\d{1,3}(?:,\d{3})+|(?!0+(?!\d))\d{1,4})(?!\d)
(?<!\d)0*\K(?:\d{1,3}(?:,\d{3})+|(?!0+(?!\d))\d{1,4})(?!\d|.*\b\d{4}Q[1-4]\b)
(?<!\d)0*\K(?:\d{1,3}(?:,\d{3})+|(?!0+(?!\d))\d{1,4})(?!\d)(?![\s\S]*\b\d{4}Q[1-4]\b)

for example in following list I want to bookmark my first regex values but my first regex select last line too (quarter line) and i don't like this!

alcatel5,457,850

Samsung

SAMSUNG4,702,078

Sagem

SAGEM2,114,184

NECNEC643,636

1997Q3
/////////////////////////

Solution

  • As stated as comment try:

    ^(?!\d{4}Q[1-4])[^\d\n]+\K[\d,]+
    

    See at regex101.com/r/A5gZud/latest

    ^ Asserts position at start of string

    (?!...) exclude cases when ...

    • \d{4}Q[1-4] four digits followed by 1 to 4 Q

    [^\d\n]+ find anything BUT numbers while not skipping a line ...

    \K ... and keep this out of the match

    [\d,]+ match digits and ,