1

I am aware that there are quite a few similar threads on this and I've tried the solutions but I can't seem to solve my problems despite reading them - please pardon me.

Could any one tell me what's wrong with these two codes below such that it isn't able to fulfil my criteria of selecting only whole numbers. (refer to the two images below)

Option 1 - how to I prevent $2000.5 from being selected since it isn't a whole number?

\$\d+[^.|x](?![0-9])

enter image description here

Option 2 - This code doesn't select $2000.5 but it isn't selecting $100 (which is a whole number).

\$\d+$

enter image description here

Data

5x Item C $2.5x5, $2.50x1
1 Book $2.55
1x Table $2.59
2x Item A $2000.5x2, 10x Item B $0.5x10
1x Test $2.513, 5x Pear $100x5
$1.430
$1.50 
$1.55
10x Tee $0.5x10
50x SSS $6.5x50
$2.5, $50

Thank you very much.

1 Answer 1

1

I suggest using the following pattern:

\$\d+(?![0-9.])

This matches $, followed by a series of one or more digits. The negative lookahead at the end (?![0-9.]) ensures that we don't match a number having a decimal component.

Demo

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.