Skip to content

Instantly share code, notes, and snippets.

@inpromotion
Created March 10, 2019 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inpromotion/305fad2ee40d23238e081df1f226f3a8 to your computer and use it in GitHub Desktop.
Save inpromotion/305fad2ee40d23238e081df1f226f3a8 to your computer and use it in GitHub Desktop.
Модуль для поддержки функций регулярных выражений для Excel из MS Office
Microsoft Excel, к сожалению, не имеет поддержки RegExp по-умолчанию "из коробки", но это легко исправить с помощью VBA.
Откройте редактор Visual Basic с вкладки Разработчик (Developer) или сочетанием клавиш Alt+F11.
Затем вставьте новый модуль через меню Insert - Module и скопируйте туда текст вот такой макрофункции:
====================
Public Function RegExpExtract(Text As String, Pattern As String, Optional Item As Integer = 1) As String
On Error GoTo ErrHandl
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = Pattern
regex.Global = True
If regex.Test(Text) Then
Set matches = regex.Execute(Text)
RegExpExtract = matches.Item(Item - 1)
Exit Function
End If
ErrHandl:
RegExpExtract = CVErr(xlErrValue)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment