import Foundation
let pattern = #"(?<=\G(?!^)|\@apply) ([^\s\;]*|[\p{P}]*)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = ##"""
/* Adds custom prefix to tailwind classes */
/* https://v2.tailwindcss.com/docs/just-in-time-mode#:~:text=Don%27t%20use%20spaces%20in%20arbitrary%20values */
@apply rounded text-md;
@apply rounded text-md aaaa;
@apply grid-cols-[1fr,700px,2fr] text-[var(--mystery-var)] text-[color:var(--mystery-var)];
@apply rounded text-md w-[calc(asdasd-ssd)];
"""##
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #" tw-$1"#
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