|
|
(同じ利用者による、間の9版が非表示) |
1行目: |
1行目: |
| ([[String]]).matches [https://docs.oracle.com/javase/jp/8/docs/api/java/lang/String.html#matches-java.lang.String-]<br>
| | "[[String]]".matches [https://docs.oracle.com/javase/jp/8/docs/api/java/lang/String.html#matches-java.lang.String-] |
| public boolean matches(String regex)
| |
|
| |
|
| 正規表現を利用して指定文字列と一致するか調べます。
| | [[正規表現]]を利用して適切な文字列かどうか真偽する。ユーザによる入力データが適切かどうかの判断などに利用できる。 |
|
| |
|
| if (s.matches("ho[gbw]e")) { | | String s1 = "Java and Python and C++."; |
| System.out.println("It matches!");
| | if (s1.matches("^[Jj]ava.*")) { |
| | System.out.println("ture"); |
| } | | } |
| | |
| | //endsWith(), startsWithの代用 |
| | s1.matches("Ma.*"); |
| | s1.matches(.*ful"); |
2019年7月1日 (月) 23:11時点における最新版
"String".matches [1]
正規表現を利用して適切な文字列かどうか真偽する。ユーザによる入力データが適切かどうかの判断などに利用できる。
String s1 = "Java and Python and C++.";
if (s1.matches("^[Jj]ava.*")) {
System.out.println("ture");
}
//endsWith(), startsWithの代用
s1.matches("Ma.*");
s1.matches(.*ful");