Replace rear navigation in JavaScript regular expression

Asked 2 years ago, Updated 2 years ago, 14 views

const regfix1 = /(?<=\s\S*)\s*/gi;

In JavaScript, we created a regular expression like this to assign all spaces except the first space in the specified string.

However, the execution environment does not support backward search (?<=) grammar.

So I asked if there is a regular expression that can replace all regular expressions using back search, or if there is another expression that can specify the above conditions, "all spaces except the first space."

javascript

2022-09-22 19:08

1 Answers

const regfix1 = /(?<=\s\S*)\s+/gi;
a = 'abc def ghi jkl'
console.log(a.replace(regfix1, 'XX'))
abc defXXghiXXjkl

Regular expressions

/(?<=\s\S*)\s+/gi;

Switch to "\s+" and it works fine.


2022-09-22 19:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.