0

I am using a language where the syntax is regex_replace(string, pattern, replacement_string).

I have a few strings which look like this s=123-21785-15643411.

I am looking for a pattern to replace s with 1232178515643411.

What would be the pattern such that I can do regex_replace(s, pattern, '') and remove the hyphens from my string?

thewhitetie
  • 233
  • 1
  • 10

2 Answers2

0

Example could be like:

s="123-21785-15643411";

s = s.replace(/-/g,"");

console.log(s);
Mohsen Alyafei
  • 2,476
  • 3
  • 13
  • 26
0

In Python 3:

import re
s = "123-21785-15643411"
regex = r"-"
res = re.sub(regex, '', s)
print(res)

Returns:

1232178515643411

but string methods are much more direct:

print(s.replace('-', ''))

Giving the same result

Gustav Rasmussen
  • 2,802
  • 3
  • 12
  • 33