這是一個包含公式和生物代碼的巨大文件中的樣本。有些線路開始與以下字符:如何編寫這個正則表達式?
Sheep"-head`ed, // followed by some normal words
Mon`o*car*bon"ic, // followed by some normal words
mon`o*car"di*an, // followed by some normal words
Pol`y*chro"mate, // followed by some normal words
sheep"cot`, // followed by some normal words
baad, // followed by some normal words
我在正則表達式新。現在我正在嘗試使用TPerlRegEx(a wrapper of PCRE library)。我需要提取:
Sheep"-head`ed,
Mon`o*car*bon"ic,
mon`o*car"di*an,
Pol`y*chro"mate,
sheep"cot`,
baad,
你能幫我寫一個正則表達式嗎?
非常感謝。
編輯:
謝謝大家的幫助。如果一個正常的是他們之間:
Sheep"-head`ed, // followed by some normal words
Mon`o*car*bon"ic, // followed by some normal words
New test, //I do not want two or more than two words that end with comma.
mon`o*car"di*an, // followed by some normal words
Pol`y*chro"mate, // followed by some normal words
sheep"cot`, // followed by some normal words
baad, // I want this one word that ends with comma
我還是想:
Sheep"-head`ed,
Mon`o*car*bon"ic,
mon`o*car"di*an,
Pol`y*chro"mate,
sheep"cot`,
baad, // I want this ONE word that ends with comma.
再次感謝您。
爲什麼你需要一個正則表達式?爲什麼不把每行都分割成'/ \ s + /'? – 2012-04-20 14:49:41
是你的例子中的特殊字符實際上是你的字符串,還是他們嘗試正則表達式的語法? – Kip 2012-04-20 14:56:03
@Kip謝謝,他們是真正的樣本。 – Warren 2012-04-20 14:57:51