I have a JS file which was created using browserify, and it uses the ??
operator. The problem is, the environment where I am executing this JS file doesn’t support that operator yet.
Is there any way I can go through the file, search and replace it using regex?
The change would be from this:
JavaScript
x
2
1
object.error ?? 0
2
To this:
JavaScript
1
2
1
x == undefined ? 0 : object.error
2
Advertisement
Answer
Is it JS or Python?
Anyway, try capturing the line with:
JavaScript
1
2
1
(([^ t]+)[ t]*??[ t]*d+)
2
This expression returns two groups:
- The line to be replaced
- The
object.error
You then need to replace group#1 by x == undefined ? 0 : group#2