80,471
社区成员




protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
textView = findViewById( R.id.textview );
editText = findViewById( R.id.edittext );
button1 = findViewById( R.id.button );
button1.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
String str = textView.getText().toString();
String regEx = "--sector:\\s*?(\\d+),\\s*block:\\s*\\d+,\\s*key\\s*type:[A-Z],\\s*key\\s*count:\\s*\\d+\\s*Found";
Pattern pattern = Pattern.compile( regEx );
Matcher matcher = pattern.matcher( str );
boolean s = matcher.matches();
int i = (s==true?1:0);
//System.out.print( s );
String str2 = textView.getText().toString();
String regEx2 = "type:([AB]),\\\\s*key\\\\s*count:\\\\s*\\\\d+\\\\s*Found";
Pattern pattern2 = Pattern.compile( regEx2 );
Matcher matcher2 = pattern2.matcher( str2 );
boolean b = matcher2.matches();
int o = (b==true?1:0);
textView.setText("No key specified, trying default keys \n" +
"--sector:13, block: 55, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:14, block: 59, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:15, block: 63, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"Found keys have been transferred to the emulator memory \n");
if(-1!= (textView.getText().toString().indexOf("Found keys have been transferred to the emulator memory")))
{
((SectorandKey) getApplication()).setI(textView.getText().toString());
((SectorandKey) getApplication()).setO(textView.getText().toString());
editText.setText("hf mf nested 1 ".toCharArray(),i,o);
}
}
} );
}
}
我是这样写的 为什么正则表达式没有截取到值呢 求大神解答一下 感谢啦public class MainActivity extends Activity {
TextView textView,tv,tv3;
EditText editText;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView =(TextView) findViewById( R.id.textview );
tv =(TextView) findViewById( R.id.tv );
tv3 =(TextView) findViewById( R.id.tv3 );
editText = (EditText)findViewById( R.id.edittext );
button1 =(Button) findViewById( R.id.button );
button1.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
String str = textView.getText().toString();
String regEx = "--sector:\\s*?(\\d+),\\s*block:\\s*\\d+,\\s*key\\s*type:[A-Z],\\s*key\\s*count:\\s*\\d+\\s*Found";
Pattern pattern = Pattern.compile( regEx );
Matcher matcher = pattern.matcher( str );
boolean s = matcher.matches();
int i = (s==true?1:0);
//System.out.print( s );
String str2 = textView.getText().toString();
String regEx2 = "type:([AB]),\\\\s*key\\\\s*count:\\\\s*\\\\d+\\\\s*Found";
Pattern pattern2 = Pattern.compile( regEx2 );
Matcher matcher2 = pattern2.matcher( str2 );
boolean b = matcher2.matches();
int o = (b==true?1:0);
textView.setText("No key specified, trying default keys \n" +
"--sector:13,block: 55, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:14,block: 59, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:15,block: 63, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"Found keys have been transferred to the emulator memory \n");
int start=str2.indexOf("--sector:")+"--sector:".length();
String data=str2.substring(start, start+2);
if(-1!= (textView.getText().toString().indexOf("Found keys have been transferred to the emulator memory")))
{
/* ((SectorandKey) getApplication()).setI(textView.getText().toString());
((SectorandKey) getApplication()).setO(textView.getText().toString()); */
editText.setText("hf mf nested 1 ".toCharArray(),i,o);
}
Pattern pattern3 = Pattern.compile("--sector:(.*)block");
Matcher m = pattern3.matcher(textView.getText().toString());
List<String> list= new ArrayList<String>();
while (m.find()) {
list.add(m.group(1));
}
Log.e("MainActivity",list.toString());
tv.setText(list.toString());
Pattern pattern4 = Pattern.compile("(?<=--sector:)\\d+",Pattern.CASE_INSENSITIVE);
Matcher m2 = pattern4.matcher(textView.getText().toString());
List<String> list2= new ArrayList<String>();
while (m2.find()) {
list2.add(m2.group());
}
tv3.setText(list2.toString());
}
catch (Exception e)
{
Toast.makeText(getApplication(),e.toString() ,Toast.LENGTH_LONG).show();
}
}
} );
}
}
Pattern pattern = Pattern.compile("(?<=--sector:)\\d+",Pattern.CASE_INSENSITIVE);
Matcher m = pattern.matcher(str);
List<String> list= new ArrayList<>();
while (m.find()) {
list.add(m.group());
}
String string="No key specified, trying default keys \n" +
"--sector:13, block: 55, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:14, block: 59, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:15, block: 63, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"Found keys have been transferred to the emulator memory \n";
int start=string.indexOf("--sector:")+"--sector:".length();
String data=string.substring(start, start+2);
"No key specified, trying default keys \n" +
"--sector:13, block: 55, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:14, block: 59, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"--sector:15, block: 63, key type:B, key count:13 \n" +
"Found valid key:[ffffffffffff] \n" +
"Found keys have been transferred to the emulator memory \n"
请问就是这些数据,想要截取Found valid key:[ffffffffffff]上面出现的--sector后面的值,就比如说现在的数据,想要得到13,有什么办法吗