Nimbocrux
Nimbocrux

Reputation: 519

Regex for any non-zero number

I'm using regex in Notepad++, recent version at time of post Nov 2016

I'm working on problem where I have dozens of text files containing financial information of wage and commission earnings. I need to find all employees that earned a commission

Files are formatted a such.

emp001smithj20150000095000 

is an example of no commission earned last year (position 17, 5 chars = "00000")

emp002jonest20151752545000

is an example of $17525 commission earned last year (position 17, 5 chars = "17525")

I've tried...

^.{16}\b[1-9]{5}\b

The rationale is that I want any non-zero number among five character word boundary that starts at position 16, but no luck. I'm obviously missing something!

Upvotes: 2

Views: 1068

Answers (2)

NRiding
NRiding

Reputation: 301

^.{16}(?!00000)

Use negative look around to find the next five characters that are not 00000

Upvotes: 2

Sebastian Proske
Sebastian Proske

Reputation: 8413

You shouldn't use word boundaries here, as your numbers are surrounded by other numbers. You will need a lookahead to check, that your 5 digit number doesn't consist of numbers only, so a way would be:

^.{16}(?=0{0,4}[1-9])\d{5}

You shouldn't try to match [1-9]{5}, this e.g. won't match 15000

Upvotes: 2

Related Questions