Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Regular Expressions letzten href vor Stichwort finden (https://www.delphipraxis.net/186894-regular-expressions-letzten-href-vor-stichwort-finden.html)

ScharfeMietze 9. Okt 2015 11:14

Regular Expressions letzten href vor Stichwort finden
 
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;

Dennis07 22. Okt 2015 05:48

AW: Regular Expressions letzten href vor Stichwort finden
 
Probiers mal mit PosEx().

nuclearping 22. Okt 2015 06:48

AW: Regular Expressions letzten href vor Stichwort finden
 
Man sollte kein RegEx nehmen, um HTML zu verarbeiten. Probiers mal mit einem DOM-Parser.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:51 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz