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
  • 36,946
  • 82
  • 271
  • 487

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
  • 35,401
  • 16
  • 78
  • 107
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392