text: Q:
  
  Adding ".js" extension using replace with regex in JavaScript
  
  Let's say I have to import statements
  // other code...
  import * as Foo from "../some/bar";
  import { baz } from './dir/qux';
  // other code...
  
  and I want to add a .js extension to the end of each of the above files in single/double quotes like so
  import * as Foo from "../some/bar.js";
  import { baz } from './dir/qux.js';
  
  in the entire code strings.
  What would be the proper way to replace with Regex in JavaScript?
  In global and case match 
  str.replace(regexp, newSubstr|function)
  String.replace docs
  Thanks.
  
  A:
  
  This seems to work  
  Find:
  /^(import[^\S\r\n].+?[^\S\r\n]from[^\S\r\n]*(["']))((?:(?!(?:\.js)?\2)[\S\s])+)(\2\s*;)/mg 
  Replace:
  $1$3.js$4 
  https://regex101.com/r/Obcf0S/1
  Readable regex  
   ^                             # BOL
   (                             # (1 start), Preamble
        import [^\S\r\n] .+? 
        [^\S\r\n] 
        from [^\S\r\n]* 
        ( ["'] )                      # (2), Delimiter
   )                             # (1 end)
   (                             # (3 start), Body
        (?:
             (?!
                  (?: \.js )?
                  \2 
             )
             [\S\s] 
        )+
   )                             # (3 end)
   ( \2 \s* ; )                  # (4), Postfix
  
  