我想寫一個正則表達式,可以從字符串中提取不同類型的字符串+數字+符號組合。該類型的字符串我想提取的是:基於this正則表達式從字符串中提取字母數字+符號組合
avs-tldr-02 this is a test
cc+asede this is a test
x86_64 this is a test
this is a test avs-tldr-02 this is a test
this is a test cc+asede this is a test
this is a test x86_64 this is a test
this is a test avs-tldr-02
this is a test cc+asede
this is a test x86_64
:
avs-tldr-02
cc+asede
x86_64
我測試的邊緣案件類型是出現在開始,中間和句子的末尾這些字符串優秀的答案,我已經在正則表達式「環視」斷言周圍涉足,並拿出了以下內容:
(?=.*[:alnum:])(?=.*[:punct:])([a-zA-Z0-9_-]+)
然而,這保持匹配S的第一個字特林 - 我明白爲什麼會發生這種情況,但是我不知道如何調整它以適合我的用例。
我該如何修改這個以獲得我正在尋找的東西/是否有其他解決此問題的方法?
你可以只使用'strsplit'和'grep':'sapply(strsplit(S,\\ S +'),grep的,圖案= '[[:PUNCT:]]' ,value = TRUE)' – alistaire