0

webpack is giving me an error when running npm run build. this is the error:

Invalid regular expression: /(?<=\.)(.*?)(?=\.)/: Invalid group (2391:33)
|                     };
|                 } else if (this.runFlag === true) {
|                     var regex = /(?<=\.)(.*?)(?=\.)/g;
                let redirectRegex =
                    this.hostToRegex.length > 0
                        ? this.hostToRegex.map(x => x.match(regex))
                        : null;
biillitil
  • 141
  • 1
  • 12
  • Use capturing, `/\.([^.]*)\./`, get Group 1. – Wiktor Stribiżew May 09 '21 at 10:33
  • how do i get group 1? so now I have const regex = /\.([^.]*)\./g; console.log(this.hostToRegex.map(x => x.match(regex))) which returns [".abcd."] but I need to get rid of the dots – biillitil May 09 '21 at 10:49
  • See [How do you access the matched groups in a JavaScript regular expression?](https://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression) or [my answer](https://stackoverflow.com/a/40782646/3832970). – Wiktor Stribiżew May 09 '21 at 10:51
  • now I get ["abcd"] but its an array and i need this as a string – biillitil May 09 '21 at 11:09
  • const regex = /\.([^.]*)\./g; console.log(this.hostToRegex.map(x => regex.exec(x)[1])) – biillitil May 09 '21 at 11:09
  • Then why are you using `g` flag at all if you need the first match? Again, see my answer. `/\.([^.]*)\./.exec(string)[1]` – Wiktor Stribiżew May 09 '21 at 11:10

0 Answers0