-2

I have a simple RE question, I want to extract dots that are in between text, but not the dots that are between decimal numbers like 4454.54. I need that to separate them from words ..

I created the following RE: [^\d+(.*?)+\d]

But it extracts the text that has dots in it!

Vidovitsch
  • 59
  • 1
  • 8
Minions
  • 5,104
  • 5
  • 50
  • 91
  • 1
    That regex doesn't match your description at all. Dots that are neither preceded nor followed by a digit would be `(?<!\d)\.(?!\d)`. Use a regex explainer like https://regex101.com/ to help you along. – jonrsharpe Mar 03 '18 at 16:38
  • Check it here: https://pythex.org/ – Minions Mar 03 '18 at 16:39
  • Thanx for the solution, could you propose to me any resource to learn how to built a RE ? – Minions Mar 03 '18 at 16:40
  • You mean other than the one I just did? On SO, perhaps: https://stackoverflow.com/q/4736/3001761, https://stackoverflow.com/q/22937618/3001761. I'd recommend research. – jonrsharpe Mar 03 '18 at 16:42
  • You asked about a resource to learn about Regex. Try www.rexegg.com - in my opinion quite a good tutorial. – Valdi_Bo Mar 03 '18 at 17:03

1 Answers1

1

The regex proposed by jonrsharpe fails to match a dot after the number, and I think, it should be matched.

So my proposition is: \.(?!\d) - a literal dot, not followed by a digit.

For example source text:

Take a positive number. For example 4454.54. Then subtract 4.5 from it.

it matches 3 dots, following:

  • number,
  • 4454.54,
  • it.

As you expect, both dots serving as decimal points (in 4454.54 and 4.5) are not matched.

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41