XML ファイルの内容を検証するために正規表現を使用しようとしています。私は次のことを試しました。
XML ファイル 1:
<start>
<hi>2dsds</hi>
<expected xmlns="sw2223" xmlns=\"\">123</expected>
<bye>2dsds</bye>
XML ファイル 2:
<start>
<hi>2dsds</hi>
<Somethingexpected xmlns="sw2223" xmlns=\"\">123</Somethingexpected>
<bye>2dsds</bye>
<expected>
これら 2 つの XML ファイルでは、フィールドとの間の内容が気になり<Somethingexpected>
ます。そのコンテンツ間のすべてのフィールドを数値にしたい。
有効な内容:
<Somethingexpected xmlns="sw2223" xmlns=\"\">123</Somethingexpected>
<Expected xmlns=\"\">123</Expected>
<expected xmlns=\"\">123</expected>
無効なコンテンツ:
<Somethingexpected xmlns="sw2223" xmlns=\"\">123a</Somethingexpected>
<Expected xmlns=\"\">avbv 123</Expected>
<expected xmlns=\"\">**(***</expected>
タグ間の数字以外は何も必要ありません(スペースもありません)
これらの正規表現を使用してみました:
if(String.matches(".*<.*[eE]xpected.*?>.*[a-zA-Z].*<.*") ||
String.matches(".*<.*[eE]xpected.*?>.*[^0-9].*<.*"))
return invalid;
else
return valid;
入力 1:
<Somethingexpected xmlns="sw2223" xmlns=\"\">123</Somethingexpected>
入力 2:
<start>
<hi>2dsds</hi>
<Somethingexpected xmlns="sw2223" xmlns=\"\">123</Somethingexpected>
<bye>2dsds</bye>
入力 1 の場合、これはvalidと表示されます。入力 2 の場合、無効と表示されます
どこが間違っているのかわかりません。誰かが私の正規表現を修正できますか?