2

これは、数式とバイオコードを含む巨大なファイルからのサンプルピースです。一部の行は次の文字で始まります。

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(PCREライブラリのラッパー)を使用しようとしています。抽出する必要があります:

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.

ありがとうございました。

4

2 に答える 2

3

生の正規^[^,]+,表現はperlの正規表現です:/^[^,]+,/

  • ^ 行頭に一致
  • [^ ,]+できるだけ多くの非コンマ、非スペースに一致します。
  • , カンマと一致します
于 2012-04-20T14:50:53.397 に答える
1

指定された値で始まる行を一致させるための正規表現は次のとおりです。

/^startswith/

特殊文字をエスケープする必要があります。例えば:

/^Sheep\"\-head\`ed,/

(どの文字をエスケープする必要があるかを正確に思い出せませんが、一般に、アルファベット以外の文字は、必要がなくてもエスケープできます。)

1つの正規表現をどの例とも一致させるには、次のようorに一緒に使用できます。|

/^(Sheep\"\-head\`ed,|Mon\`o\*car\*bon\"ic,|...)/
于 2012-04-20T14:51:13.140 に答える