-1

I am getting long string with multiple occurances of pattern './.'. The string has dates as well in a format of dd.mm.yyyy.

First I tried with javascript replace method as:

str.replace('./.', ''). But it replaced only first occurance of './.'

Then I tried another regex which replaces special characters but it didn't work as it replaced '.' within dates as well.

How do I replace multiple occurances of a pattern './.' without affecting any other characters of a string ?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Valay
  • 1,991
  • 2
  • 43
  • 98

4 Answers4

0
  1. Escape . and d \
  2. Add a g for global

Like this

str = str.replace(/\./\./g, '');
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

. is a special character in a regexp, it matches any character, you have to escape it.

str.replace(/\.\/\./g, '');
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

Use this simple pattern:

/\.\/\./g 

to find all "./." strings in your text.

RyanB
  • 1,287
  • 1
  • 9
  • 28
0

Try it :

str.replace(/\.\/\./g, '');
Satender K
  • 571
  • 3
  • 13