This is an old revision of the document!
Prüft ob ein Value auf ein Pattern passt. Die RegExp-Objekte werden gecached. Interessant für SQL
Download udf_rxlib.bas (V-1.0.0)
Manchmalwäre es ganz praktisch in SQL mit Regulären Ausdrücken arbeiten zu können. Dazu habe ich eine Funktionssammlung erstellt, die es mit erlaubt genau dies zu tun. Die RegExp-Objekte werden dabei als statische Objekte gespeichert, damit nicht für jede Zeile ein neues Objekt angelegt werden muss. Es können in einem SL mehrere verschiedene Patterns verwendet werden. Diese kann man mit einem Index ansteuern, damit jeder für sich gespeichert wird.
Boolean = rxMatch(value [,pattern])
Public Function rxMatch( _ ByVal iValue As Variant, _ Optional ByVal iPattern As String = Empty _ ) As Boolean
SELECT t.* FROM myTable t WHERE rxMatch(t.username, '/^ruedi$/i'); ID | USERNAME ---|--------- 7 | Ruedi SELECT t.* FROM myTable t WHERE rxMatch(t.username, '/ruedi/i'); ID | USERNAME ---|----------- 4 | Hansruedi 5 | Hans-Ruedi 7 | Ruedi SELECT t.*, rxMatch(t.username, '/ruedi/i') AS like_ruedi, rxMatch(t.username, '/ueli/i') AS like_ueli, rxMatch(t.username, '/hans/i') AS like_hans, rxMatch(t.username, '/hans-?(ueli|peter)/i') AS test4 FROM myTable t; ID | USERNAME | like_ruedi | like_ueli | like_hans | test4 ---|------------|------------|-----------|-----------|------ 1 | Hans | 0 | 0 | -1 | 0 2 | Hans-Ueli | 0 | -1 | -1 | -1 3 | Hansueli | 0 | -1 | -1 | -1 4 | Hansruedi | -1 | 0 | -1 | 0 5 | Hans-Ruedi | -1 | 0 | -1 | 0 6 | Ueli | 0 | -1 | 0 | 0 7 | Ruedi | -1 | 0 | 0 | 0 8 | Peter | 0 | 0 | 0 | 0 9 | Hanspeter | 0 | 0 | -1 | -1 10 | Hans-Peter | 0 | 0 | -1 | -1
Result = rxLookup(value [,pattern [,iPosition]])
Public Function rxLookup( _ ByVal iValue As Variant, _ Optional ByVal iPattern As String = Empty, _ Optional ByVal iPosition As Long = 0 _ ) As String
SELECT t.username, rxLookup(t.username, '/(ruedi)/i', -1) AS Ruedi FROM myTable t WHERE rxMatch(t.username, '/(ruedi)/i'); username | Ruedi -----------|------ Hansruedi | ruedi Hans-Ruedi | Ruedi Ruedi | Ruedi
Result = rxReplace(value [,pattern [,iPosition]])
Public Function rxReplace( _ ByVal iValue As Variant, _ Optional ByVal iPattern As String = Empty, _ Optional ByVal iReplace As String = Empty _ ) As String
SELECT t.username, rxReplace(t.username, '/(hans)([-\s]?)ruedi/i', '$1$2Peter') AS Ruedi FROM myTable t WHERE rxMatch(t.username, '/(ruedi)/i'); username | Ruedi -----------|----------- Hansruedi | HansPeter Hans-Ruedi | Hans-Peter Ruedi | Ruedi
Unable to display file "/vba/functions/udf_rxlib.bas": It may not exist, or permission may be denied.