import Foundation
let pattern = #"(\<li\>\<a target.+?\>)(.+)(\<\/a\>\<\/li\>)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
Функция Blue
Функция ChrW [VBA]
Функция CreateUnoDialog
Функция CurDir
Функция Дата
Функция DateSerial
Функция DateValue
Функция Day
Функция DDB [VBA]
Функция Dir
Функция Eof
Функции обработки ошибок
Функция FileAttr
Функция FileDateTime
Функция FileExists
Функция FileLen
Функция FormatDateTime [VBA]
Функция FormatNumber [VBA]
Функция FreeFile
Функция FV [VBA]
Функция GetAttr
Функция Green
Функция InStrRev [VBA]
Функция Input [VBA]
Функция InputBox
Функция IPmt [VBA]
Функция IRR [VBA]
Функция Loc
Функция Lof
Функция MIRR [VBA]
Функция Month
Функция MonthName [VBA]
Функция NPer [VBA]
Функция NPV [VBA]
Числовые функции
Функция Pmt [VBA]
Функция PPmt [VBA]
Функция PV [VBA]
Функция QBColor
Функция Rate [VBA]
Функция Red
Функция RGB
Функция RGB [VBA]
Функция Round [VBA]
Функция Seek
Функция SLN [VBA]
Функция StrConv [VBA]
Функция StrReverse [VBA]
Функция SYD [VBA]
Функция WeekDay
Функция WeekdayName [VBA]
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$2"#
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