import Foundation
let pattern = #"^([ \t]*)import [*] as (\w+) from (?:(['])((?:(?:\.)+|[^\n\r'\\]+)+)[']|(["])((?:(?:\.)+|[^\n\r'\\]+)+)["])"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
import * as Atblock from "./atblock"
import * as Atrule from "./atrule"
import * as Supports from "./supports"
import * as Node from './node';
import * as Root from './root'
import Null from './null'
import * as Each from './each'
import * as If from './if'
import * as Call from './call'
import * as UnaryOp from './unaryop'
import * as BinOp from './binop'
import * as Ternary from './ternary'
import * as Block from './block'
import * as Unit from './unit'
import * as String from './string'
import * as HSLA from './hsla'
import * as RGBA from './rgba'
import * as Ident from './ident'
import * as Group from './group'
import * as Literal from './literal'
import * as Boolean from './boolean'
import * as Return from './return'
import * as Media from './media'
import * as QueryList from './query-list'
import * as Query from './query'
import * as Feature from './feature'
import * as Params from './params'
import * as Comment from './comment'
import * as Keyframes from './keyframes'
import * as Member from './member'
import * as Charset from './charset'
import * as Namespace from './namespace'
import * as Import from './import'
import * as Extend from './extend'
import * as Object from './object'
import * as Function from './function'
import * as Property from './property'
import * as Selector from './selector'
import * as Expression from './expression'
import * as Arguments from './arguments'
import * as Atblock from './atblock'
import * as Atrule from './atrule'
import * as Supports from './supports'
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1import $2 from $3$5$6$4$3$5"#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression