ich möchte folgendes:
Mein Programm liest z.B. folgende Datei ein:
test.txt Inhalt:
Code: Alles auswählen
hallo
hello
hillo
hollo
hullo
Muster:
Code: Alles auswählen
h(.)llo
Code: Alles auswählen
a
e
i
o
u
Code: Alles auswählen
hallo
hello
hillo
hollo
hullo
Code: Alles auswählen
h(.)llo
Code: Alles auswählen
a
e
i
o
u
Code: Alles auswählen
hi.s="hallo"+#CRLF$+"hello"+#CRLF$+"hillo"+#CRLF$+"hollo"+#CRLF$+"hullo"
CreateRegularExpression(0, "(?im)^h.{1}llo")
; Wir müssen ein String-Array bereitstellen
Dim ausgabe.s(0)
n=ExtractRegularExpression(0, hi, ausgabe()) ; extrahiert alle Übereinstimmungen
; n enthält die Anzahl der Matches
For i=1 To n
Debug ausgabe(i-1)
Next
Code: Alles auswählen
Macro Happy
;-)
EndMacro
Happy End
Code: Alles auswählen
IsRegularExpression(0) ; wird benoetigt um die lib einzubinden
ImportC ""
pcre_compile(pattern.s,options,*errptr,*erroffset,*tableptr)
pcre_exec(*pcre,*extra,subject.s,length,startoffset,options,*ovector,ovecsize)
pcre_get_substring(subject.s,*ovector,stringcount,stringnumber,*stringptr)
pcre_free_substring(*stringptr)
EndImport
pattern.s = "h(.)ll(.)"
subject.s = " hhlld"+#CRLF$+"hallu"+#CRLF$+"hlll "+#CRLF$+"hllld"+#CRLF$+"holla"
len = Len(subject)
offset = 0
error = 0
erroffset = 0
Dim ovec(30)
regex = pcre_compile(pattern,0,@error,@erroffset,0)
count = pcre_exec(regex,0,subject,len,offset,0,@ovec(),30)
If count < 0
Debug PeekS(error) + " -> " + PeekS(@pattern + erroffset)
End
EndIf
While count > 0
pcre_get_substring(subject,ovec(),count,1,@first_sub)
pcre_get_substring(subject,ovec(),count,2,@second_sub)
offset = ovec(1)
all.s = PeekS(@subject + ovec(0),ovec(1)-ovec(0))
all + " ("
all + PeekS(first_sub)
all + ") ("
all + PeekS(second_sub)
all + ")"
Debug all
pcre_free_substring(first_sub)
pcre_free_substring(second_sub)
count = pcre_exec(regex,0,subject,len,offset,0,@ovec(),30)
Wend
Das was Marie23 machen möchte, ist doch auch mit PB-Befehlenedel hat geschrieben:Es gibt keine moeglichkeit mit pb befehlen, man kann aber
die api von pcre benutzen.
Code: Alles auswählen
Dim result$(0)
If Not CreateRegularExpression(0,"h(.)llo")
Debug "Fehler: " + RegularExpressionError()
End
EndIf
Restore Datei
Repeat
Read line$ ; line$ = ReadString() um aus Datei zu lesen
count = ExtractRegularExpression(0, line$, result$())
If count
For i = 0 To count-1
match$ = Mid( result$(i), 2, 1 ) ; "h" und "llo" aus result$(i) entfernen
Debug match$
Next i
EndIf
Until line$ = "" ; Until EOF
DataSection
Datei:
Data.s "hallo"
Data.s "hello"
Data.s "hillo"
Data.s "hollo"
Data.s "hullo"
Data.s "h1llo h2llo h3llo h4llo"
Data.s ""
EndDataSection
Code: Alles auswählen
Dim result$(0)
If Not CreateRegularExpression(0,"h(.)ll(.)")
Debug "Fehler: " + RegularExpressionError()
End
EndIf
Restore Datei
Repeat
Read line$ ; line$ = ReadString() um aus Datei zu lesen
count = ExtractRegularExpression(0, line$, result$())
If count
For i = 0 To count-1
match$ = result$(i)+" ("+Mid(result$(i),2,1)+") ("+Mid(result$(i),5,1)+")"
Debug match$
Next i
EndIf
Until line$ = "" ; Until EOF
DataSection
Datei:
Data.s " hhlld", "hallu", "hlll ", "hllld", "holla"
Data.s ""
EndDataSection