Hirdetés
-
PROHARDVER!
A Microsoft Excel topic célja segítséget kérni és nyújtani Excellel kapcsolatos problémákra.
Kérdés felvetése előtt olvasd el, ha még nem tetted.
Új hozzászólás Aktív témák
-
válasz
Delila_1
#35525
üzenetére
Használatra példák:
=RegExExtract(A1)- kiszedi a valamelyik nyitó ([{ és valamelyik záró )]} közül a szöveget=RegExExtract(A1,"","@")- kiszedi az emailcím elejéről a nevet=RegExExtract(A1,"@","")- kiszedi az emailcím végéről a szervert=RegExExtract(A1,"[","]", True)- kiszedi a szögletes zárójeles szöveget (úgy hogy a zárójelet is visszaadja)RegExExtract.bas
Option Explicit
Dim rx As Object
Const REPLACABLE = "()[]{}-+*.\"
Public Function RegExExtract(Text As String, Optional StartMarker As String = "([{", Optional EndMarker As String = "}])", Optional Include As Boolean = False) As String
Dim sm As String
sm = ""
If StartMarker <> "" Then
Dim ix
For ix = 1 To Len(StartMarker)
If InStr(REPLACABLE, Mid(StartMarker, ix, 1)) > 0 Then
sm = sm & "\" & Mid(StartMarker, ix, 1)
Else
sm = sm & Mid(StartMarker, ix, 1)
End If
Next
sm = "[" & sm & "]"
End If
Dim em As String
Dim im As String
em = ""
im = ""
If EndMarker <> "" Then
For ix = 1 To Len(EndMarker)
If InStr(REPLACABLE, Mid(EndMarker, ix, 1)) > 0 Then
em = em & "\" & Mid(EndMarker, ix, 1)
Else
em = em & Mid(EndMarker, ix, 1)
End If
Next
im = "[^" & em & "]*"
em = "[" & em & "]"
Else
im = ".*"
End If
Dim rxt As String
If Include Then
rxt = "(" & sm & im & em & ")"
Else
rxt = sm & "(" & im & ")" & em
End If
If rx Is Nothing Then
Set rx = CreateObject("vbscript.regexp")
rx.IgnoreCase = True
rx.Global = True
rx.MultiLine = True
rx.Pattern = rxt
ElseIf rx.Pattern = rxt Then
'cached
Else
rx.Pattern = rxt
End If
Dim Matches
Set Matches = rx.Execute(Text)
If Matches.Count > 0 Then
Dim M
For Each M In Matches.Item(0).SubMatches
If M <> "" Then
RegExExtract = M
Exit For
End If
Next
Else
RegExExtract = ""
End If
End Function
Új hozzászólás Aktív témák
- ÚJ AKKU! Ár/ÉRTÉK BAJNOK! Dell Latitude 5330 i3-1215U 6mag! 16GB 512GB 13.3" FHD 1 év gar
- ÁRGARANCIA!Épített KomPhone Ryzen 5 7600X 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- Dell Latitude Core i5 - i7 - 6-7-8-10-11-12-13. gen. üzleti kategóriás notebookok számlával
- Keresünk iPhone 14/14 Plus/14 Pro/14 Pro Max
- HIBÁTLAN iPhone 14 Pro 256GB Gold -1 ÉV GARANCIA - Kártyafüggetlen, MS3919
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopszaki Kft.
Város: Budapest
Fferi50

