2017-12-18 15 views
0

"\[@(.*?)\]"のパターンを使用して既に"[@foo]"から"applicant_data/contact_number[@foo]" w/cに一致する.NET正規表現が必要です。Regex特定の文字列を除外

は、しかし、私はパターンに一致しない"applicant_data/contact_number[@foo=2]"ように例外を作りたいです。それでは、正規表現は、有効な英数字([@ bar]、[@ theVar]、[@ zoo $ 6])を取得し、[@ bar = 1]、[@ theVar = 3] ?

+0

あなたは何を試しましたか? – Sefe

+0

\ [@(。*?)[^ = 2] \] – Sunil

+0

単語 'foo'は定数ですか?また、番号「2」または任意の数だけ除外したいとしますか?私は "\ [@(。*?)\]" – Gurman

答えて

1

あなたはこれを試すことがあります。

\[@[\w-]+(?!=)\] 

説明:

"\[" &  ' Match the character “[” literally 
"@" &  ' Match the character “@” literally 
"[\w-]" & ' Match a single character present in the list below 
       ' A “word character” (Unicode; any letter or ideograph, digit, connector punctuation) 
       ' The literal character “-” 
    "+" &  ' Between one and unlimited times, as many times as possible, giving back as needed (greedy) 
"(?!" &  ' Assert that it is impossible to match the regex below starting at this position (negative lookahead) 
    "=" &  ' Match the character “=” literally 
")" & 
"\]"   ' Match the character “]” literally 

は、この情報がお役に立てば幸い!

+0

あなたが唯一のような答えを拡大する可能性のあるチャンスを更新取得 "" から" FOOを@ [FOO] "[ "でかつ成功しました"]の@ "が先行する」(記号=意味はなし)、" 単語文字を見つける"。 – james

+0

てください... ''(?<= @ [\)\ + W(? + W \ [^ \]] * \]) '... – Cylian

+0

おかげで@Cylianが – james

1

は、この正規表現を試してみてください:

\[@(?![^\]]*?=).*?\]

Click for Demo

説明:

  • \[@から[@文字通り
  • (?![^\]]*?=)と一致します - 改行文字
  • \]以外の任意の文字の一致0+出現 - - 否定先読みが=は、次の]
  • .*?前に、どこにも存在しないことを確認するために一致する]文字通り
+0

おかげ@Gurman "= 2" 試してみた – james

+0

は\ [@(?![^ \]] *?=」)のように思える。*?\] "働くだろう。 – james

+0

@jamesソリューション – Gurman

関連する問題