Autor Beitrag
Ebil
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Fr 29.04.11 15:57 
Hi leute,

Ich will mit Regex einen bestimmten teil in z.B einem quelltext eindeutig identifizieren.
beispielweise habe ich dieses pattern
ausblenden Quelltext
1:
<h2><span class="entry-date alignright">[0-9.]{1,}</span><a href="					

Bei diesem string :
ausblenden Quelltext
1:
<h2><span class="entry-date alignright">05.28</span><a href="					


Will aber nur den markierten bereich als match.value haben. Ist das mit irgendeiner regex funktion möglich? Hab schon ne weile gesucht und nichts gefunden..

LG Ebil
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 29.04.11 16:05 
Moin!

Welche RegEx-Lib benutzt du denn? :nixweiss: Stück Code wäre nicht schlecht. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Ebil Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Fr 29.04.11 16:17 
Das ist die delphi interne, keine ahnung ab welcher version die dabei ist. in der uses klausel hab ich einfach "RegularExpressions"

ausblenden Delphi-Quelltext
1:
2:
3:
4:
//Pattern definieren:
regex.Create('<h2><span class="entry-date alignright">[0-9.]{1,}</span><a href="',[]);
//Und nen match aus dem clipboard zb.
match := regex.Match(Clipboard.AsText);
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 29.04.11 16:28 
Du musst den auszuwählenden Bereich umklammern, also:

user profile iconEbil hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Quelltext
1:
<h2><span class="entry-date alignright">([0-9.]{1,})</span><a href="					

Da auch mehrere Bereiche in Klammern gesetzt werden können, müsste es im Ergebnis irgendwo eine Liste von Werten geben, von denen einer der Wert der Gruppe ist.

Edit: Klammer richtiggestellt


Zuletzt bearbeitet von Yogu am Sa 30.04.11 15:08, insgesamt 1-mal bearbeitet
finalizat0r
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 24
Erhaltene Danke: 1



BeitragVerfasst: Sa 30.04.11 12:59 
ausblenden Quelltext
1:
<h2><span class="entry-date alignright">([^\r\n\f]*)<\/span><a href="					


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
begin
  R := TRegExpr.Create;
  try
    R.Expression := '<h2><span class="entry-date alignright">([^\r\n\f]*)<\/span><a href="';

    if R.Exec('<h2><span class="entry-date alignright">[0-9.]{1,}</span><a href="'then
      ShowMessage(R.Match[1]);
  finally
    R.Free;
  end;
end;


Gruß