2011-08-05 21 views
5

bir karakter dizisinin hariç ve ben regex için istediğiniz tüm tüm http ..C# Normal İfade ipi bir koleksiyonu var

href = "http://www.test.com/cat ile başladı toplamaktır /1-one_piece_episodes/"href="http://www.test.com/cat/2-movies_english_subbed/"href="http://www.test.com/cat/3-english_dubbed/"href="http : //www.exclude.com"

bu benim düzenli ifade kalıptır ..

href="(.*?)[^#]" 

ve iade bu

href = "http://www.exclude.com" gibi alanı içine dahil olduğu maçları .. son maçında hariç veya hariç için desen ne

href="http://www.test.com/cat/1-one_piece_episodes/" 
href="http://www.test.com/cat/2-movies_english_subbed/" 
href="http://www.xxxx.com/cat/3-english_dubbed/" 
href="http://www.exclude.com" 

DÜZENLEME: birden dışlama

href="((?:(?!"|\bexclude\b|\bxxxx\b).)*)[^#]" 
+0

url 'ister miydin http:// www.test.com/fish/exclude' dahil edildi mi? "http: // www.exclude.co.uk" veya "http: // www.exclude.test.com ' –

cevap

11

@ridgerunner ve bana sağlamak için normal ifadeler değiştirecek:

href="((?:(?!\bexclude\b)[^"])*)[^#]" 

O yeter ki # yılında bitmez kelimesini exclude içermeyen tüm href özellikleri ile eşleşen.

Açıklama:

href="  # Match href=" 
(   # Capture... 
(?:  # the following group: 
    (?!  # Look ahead to check that the next part of the string isn't... 
    \b  # the entire word 
    exclude # exclude 
    \b  # (\b are word boundary anchors) 
)  # End of lookahead 
    [^"]  # If successful, match any character except for a quote 
)*  # Repeat as often as possible 
)   # End of capturing group 1 
[^#]"  # Match a non-# character and the closing quote. 

birden "yasak kelimeleri" izin vermek için:

href="((?:(?!\b(?:exclude|this|too)\b)[^"])*)[^#]" 
+0

" href = "((? :(?!" | \ bexclude \ b)' yi ayrıştırma.) * [^ #] "" - Yeterli değil) 's şimdi tamam .. sadece açıklama okuyun .. href = "((? :(?!" | \ bexclude \ b).) *) [^ # ] " –

+0

ek soru efendim .. ek dizgiyi hariç tutmama ne dersiniz? Xxxx **? –

+0

gerekli değil .. ben çözdüm .. teşekkürler .. –

0

bu işi yapar mı?

href="(?!http://[^/"]+exclude.com)(.*?)[^#]" 
2

(sen onları tırnak kaçış sürece) ama sen de regex olmadan bunu geçerli bir dize gibi görünmüyor girişiniz:

string input = "href=\"http://www.test.com/cat/1-one_piece_episodes/\"href=\"http://www.test.com/cat/2-movies_english_subbed/\"href=\"http://www.test.com/cat/3-english_dubbed/\"href=\"http://www.exclude.com\""; 

List<string> matches = new List<string>(); 

foreach(var match in input.split(new string[]{"href"})) { 
    if(!match.Contains("exclude.com")) 
     matches.Add("href" + match); 
}