Last active
August 1, 2022 07:46
-
-
Save sdkfz181tiger/6eef5d72e8b74a0a28b8 to your computer and use it in GitHub Desktop.
Regex覚え書き
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ozateck.regex; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.util.Log; | |
import android.view.Menu; | |
public class MainActivity extends Activity { | |
private static String TAG = "myTag"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//判定する文字列 | |
String str = "Something[Hell]Anything"; | |
//判定するパターンを生成 | |
String regex = "\\[.*\\]"; | |
Pattern p = Pattern.compile(regex); | |
Matcher m = p.matcher(str); | |
//画面表示 | |
if(m.find() == true){ | |
String group = m.group(); | |
int s = m.start(); | |
int e = m.end(); | |
Log.d(TAG, "s:" + s); | |
Log.d(TAG, "e:" + e); | |
Log.d(TAG, "group:" + group); | |
}else{ | |
Log.d(TAG, "can't find..."); | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment