0

I saw this Regex replace `a.b` to `a. b`? I don't understand it's for Python not for Javascript or it isn't well explained.

I know how to split "a.b" to ["a" "." "b"] with

regex = /(\.)/;
test = "a.b";
results = test.split(regex);

I can't see what regex to get

["a" ".b"]
user310291
  • 35,095
  • 76
  • 252
  • 458

1 Answers1

2

You could split by the positive lookahead of a dot.

var string = "a.b",
result = string.split(/(?=\.)/);

console.log(result);
Murat Karagöz
  • 31,071
  • 13
  • 78
  • 104
Nina Scholz
  • 351,820
  • 24
  • 303
  • 358