Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は正規表現が苦手で、この数値範囲をどのように行うかがわかりません。
編集: あいまいで申し訳ありません。入力された文字列が 2000 から 9999 の数値範囲内にあるかどうかを確認する必要があります。その前後に数字はありません。
正規表現として、次のように書くことができます
[2-9][0-9][0-9][0-9]
また
[2-9][0-9]{3}
[2-9]\d{3}
[2-9]\p{Digit}{3}
これにより、先行ゼロがないと仮定して、2000から9999までのすべての数値が得られます。つまり、002000または+2000は一致しません。
私がすることは
int i = Integer.parseInt(text); if (2000 <= i && i <= 9999) // ok.