Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Keep only numbers with comma separator in numerical lines

I have some values like following:

630,465
theGlobe
504,685
OpenDiary
Open
Diary
17,738
JUNE
1998
/////////////////////////
Bolt
bolt3,270,300
Classmates
1,509,260

Now i want to remove extra content from numerical lines.
for example I want to remove bolt from bolt3,270,300

I tried following regex:
Find What:
^.?(\b\d{1,3}(?:,\d{3})\b).*
Replace With:
$1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but this regex remove bolt3 from bolt3,270,300

I tried following regex too:
Find What:
^.?(\d{1,3}(,\d{3})).*
Replace With:
$1

but this regex remove 8 from 1998

How to fix this?

>Solution :

You can use

^.*?(?<!\d)(?<!\d,)(\d{1,3}(?:,\d{3})*)(?!,?\d).*

See the regex demo.

Details:

  • ^ – start of a line
  • .*? – any zero or more chars other than line break chars as few as possible
  • (?<!\d) – no digit allowed immediately on the left
  • (?<!\d,) – no digit and comma allowed immediately on the left
  • (\d{1,3}(?:,\d{3})*) – Group 1 ($1): one, two or three digits and the zero or more occurrences of a comma + three digits
  • (?!,?\d) – no digit or comma + digit allowed immediately on the right
  • .* – any zero or more chars other than line break chars as many as possible.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading