Einzelnen Beitrag anzeigen

ScharfeMietze

Registriert seit: 5. Mär 2014
165 Beiträge
 
Delphi 10.2 Tokyo Architect
 
#1

Regular Expressions letzten href vor Stichwort finden

  Alt 9. Okt 2015, 11:14
Hallo Leute ich möchte die letzte "href" Zeichenkette vor einem Variablen Stichwort ermitteln.

Mein Problem ist das mehrere "href" im string vorkommen.
daher funtioniert
Delphi-Quellcode:
//with TRegEx.Match(mmo1.Text,'href(.*?)' +s,[roIgnoreCase,roSingleLine]) do
// with TRegEx.Match(mmo1.Text,'(?<!(href))(?<=(href))(.+?)' +s,[roIgnoreCase,roSingleLine]) do
//with TRegEx.Match(mmo1.Text,'[^(href)]?(.*?)' +s,[roIgnoreCase,roSingleLine]) do
//with TRegEx.Match(mmo1.Text,'^(href)(.*?)' +s,[roIgnoreCase,roSingleLine]) do
//with TRegEx.Match(mmo1.Text,'([^(href)].*?)' +s,[roIgnoreCase,roSingleLine]) do
//with TRegEx.Match(mmo1.Text,'(.[^(href)]*?)' +s,[roIgnoreCase,roSingleLine]) do
//with TRegEx.Match(mmo1.Text,'[^(href)](.*?)' +s,[roIgnoreCase,roSingleLine]) do
nicht da dann alles vom ersten statt vom letztmöglichem "href" gematcht wird.

Da ich neben dem schreiben x möglichkeiten probierte und nun eine funktionierte, poste ich die Lösung gleich mit.
Eventuell gibts ja noch ahnungslose wie mich.
Delphi-Quellcode:
with TRegEx.Match(mmo1.Text,'href(?(?!.*href.*).*)' +s,[roIgnoreCase,roSingleLine]) do
 begin
   if Success then
   begin
     mmo2.Lines.Add('sucsess');
     mmo2.Lines.Add(Value);
   end;
 end;
  Mit Zitat antworten Zitat