2017-09-13 9 views
-1

Linuxのコマンドラインから、Fig.という図の参照を参照していない複数のファイル内のすべてのインスタンスを検索したいと思います。Regex/grep match on: "not this"と "that"

\ref{figと覚えていないときは、それぞれの行を探しています。正確にはFig.です。 \ref{fig:myFigure}

  • A sentence with \ref{fig:myFigure} there.
  • 正規表現

  • A sentence with Fig. \ref{fig:myFigure} there.
  • Fig. \ref{fig:myFigure}
    1. は、ケースを無視すべきである(1)及び(2)が、症例を見つける(3)及び(4)。

    +1

    何 'Fig.'と' \のref'間の改行はどうですか? –

    +0

    @ベンジャミンW。 - はい、それは可能性です。私は元の投稿から "not"と "that"のために必要な正規表現に集中するためにそれを省略しました。オプションの改行は追加するのが難しくありません。 –

    +0

    オプションの改行は、大きな違いをもたらします。これは、grepがファイルを1行ずつ表示するためです。ヌル文字のように改行の代わりに別の文字を使用するように指定すると、ファイル全体が1行と見なされるため、ファイル全体が返されます。 –

    答えて

    1

    あなたが好きな否定先読みを使用することができます。

    ^((?!Fig\. {0,1}\\ref\{fig).)*$ 
    

    https://regex101.com/r/wSw9iI/2

    Negative Lookahead (?!Fig\.\s*\\ref\{fig) 
    Assert that the Regex below does not match 
    Fig matches the characters Fig literally (case sensitive) 
    \. matches the character . literally (case sensitive) 
    \s* matches any whitespace character (equal to [\r\n\t\f\v ]) 
    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
    \\ matches the character \ literally (case sensitive) 
    ref matches the characters ref literally (case sensitive) 
    \{ matches the character { literally (case sensitive) 
    fig matches the characters fig literally (case sensitive) 
    
    関連する問題