<a class="name" href="#" onclick="changeSubscription('ID'); return false;">NAME</a>|
|
|
Edit: Tags bearbeitet
– Floyd 02.04.2011
|
|
|
| 1 |
Wie Du erst später schreibst, ist das onclick eigentlich ein onClick. Entweder änderst Du das entsprechend im Pattern oder Du gibst noch RegexOption.IgnoreCase bei den Optionen mit.
– Daniel Kuppitz 01.04.2011
|
|
|
|
<a class="name" href="#" onclick="changeSubscription('ID'); return false;">NAME</a><a class="name" href="#" onclick="changeSubscription('3zVjD6rnLfPh0oLbFfpx97-QollErvePEDvtxgUplWg'); return false;">hamburgerhaenger</a>
|
|
// <a class="name".*changeSubscription\('(?<ID>.*?)'\).*?>(?<NAME>.*?)</a>
//
// Optionen: RegexOptions.IgnoreCase | RegexOptions.Singleline
//
// Match the characters "<a class="name"" literally «<a class="name"»
// Match any single character that is not a line break character «.*»
// Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
// Match the characters "changeSubscription" literally «changeSubscription»
// Match the character "(" literally «\(»
// Match the character "'" literally «'»
// Match the regular expression below and capture its match into backreference with name "ID" «(?<ID>.*?)»
// Match any single character that is not a line break character «.*?»
// Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
// Match the character "'" literally «'»
// Match the character ")" literally «\)»
// Match any single character that is not a line break character «.*?»
// Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
// Match the character ">" literally «>»
// Match the regular expression below and capture its match into backreference with name "NAME" «(?<NAME>.*?)»
// Match any single character that is not a line break character «.*?»
// Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
// Match the characters "</a>" literally «</a>»// <a class="name".*changeSubscription\('(.*?)'\).*?>(.*?)</a>string sourceString = ...; //inhalt aus http://ideone.com/VHAIP
Regex RegexObj = new Regex("<a class=\"name\".*changeSubscription\('(?<ID>.*?)'\).*?>(?<NAME>.*?)</a>",
RegexOptions.IgnoreCase);
MatchCollection myMatchCollection = RegexObj.Match(sourceString);
foreach(Match myMatch in myMatchCollection){
Console.WriteLine("id=" + myMatch["ID"].Value);
Console.WriteLine("name=" + myMatch["NAME"].Value);
}
|
|
|
|
|
|
| 1 |
Dafür brauchst du kein Tutorial. Der Trick ist einfach ?<NameDerGruppe> in die Klammern zu schreiben. Also aus (.*?) wird (?<ID>.*?).
Hier das Tutorial: http://www.regular-expressions.info/named.html Btw, bitte bewerte die Beiträge positiv die für dich nützlich sind oder waren. – Floyd 01.04.2011
|
|
|
"." steht für ein beliebiges Zeichen
"*" für beliebig oft "?" ist eine Option und heißt "verhalte dich nicht gierig" .. ist etwas schwierig zu erklären beutet aber so viel wie "hör auf so bald du kannst". Ohne das "?" würde es bedeuten "nimm so viel du kannst". Das ist dann besonders wichtig wenn man mehrere treffer haben kann. wie zum beispiel in deinem Beispielcode. ohne fragezeichen würde ".*" von der ersten bis zu letzten zeile reichen. dh. vom ersten changeSubscription(' bis zum letzten '). mit hört es beim ersten ') wieder auf. – Floyd 01.04.2011
|
||
|
Zum Thema Bewerten. Du kannst jeden Beitrag mit den Pfeilen als Hilfreich oder Nicht Hilfreich bewerten. Zusätzlich kannst du mit dem Haken unter den Pfeilen den Beitrag kennzeichen der dir besonders hilfreich war. Codekicker sortiert dann die Beiträge so um, das die Hilfreichsten ganz oben stehen, und andere die das selbe Problem / oder ein ähnliches haben, finden sofort die nützlichsten informationen.
– Floyd 01.04.2011
|