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.
Javaで文字列から最後の整数部分を抽出する必要があります
Javaでregxを使用する
お気に入り:-
String s1="allow23"// extract 23 String s2="4code68"// extract 68
最後からの整数のみ (アルファベットの後またはアルファベットなし)
正規表現は(\\d+$). 完全なコード例は次のとおりです。
(\\d+$)
Pattern p = Pattern.compile("(\\d+)$"); Matcher m = p.matcher(str); if (m.find()) { int number = Integer.pareseInt(m.group(1)); }
これが、Java で正規表現を学ぶための良い出発点になることを願っています。