-3

I want to remove dot (.) but I don't know how can I write this pattern.

I have some text line this.

E-1-2-3.1-0-0 or E-1-2-0-2.5-0 or E-1-2-0-3.5-0

But in my text some are numbers like 2.5, 56.7. I don't want to remove these dots are they are decimals.

Just if in lines then I need to remove dot. -5.2- will be -52-

E-1-2-3.1-0-0 will E-1-2-31-0-0
E-1-2-0-2.5-0 will E-1-2-0-25-0
E-1-2-0-3.5-0 will E-1-2-0-35-0

There can inside has DOT or NOT.

Any help regarding this pattern ?

Hus R Kozk
  • 17
  • 1
  • 3

1 Answers1

1

If you only need to match dots surrounded by dash-digit and digit-dash, try positive lookarounds:

(?<=-\d)\.(?=\d-)

Demo: https://regex101.com/r/nY7fA9/1


If you need to match dots surrounded by dash-digits and digits-dash (any positive number of digits), the thing is more tricky since lookbehinds do not support quantifiers in many regex flavors. In this case you may match the prefix with a normal regex and immediately reset the match with \K:

-\d+\K\.(?=\d+-)

Demo: https://regex101.com/r/nY7fA9/2

Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40
  • Thank you answer . But if numbers will change not catching them . For example , E-1-2-53.1-0-0 or E-1-2-0-35862.5-0 or E-1-2-0-23.5-0 How can we this catch all beetwen -.....- any numbers with dot – Hus R Kozk Aug 09 '16 at 12:49