public class Test {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("data-token=\"(.*?)\"\\W+data-ad-id=\"(.*?)\"");
String text = "<div class=\"suggesttext tleft\">\n" +
" <a href=\"#\" class=\"link clearPhoneViews\"\n" +
" data-token=\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhZElEIjoiNDU4MTI0NjQ2IiwiZXhwIjoxNTQyNDkxMzAxfQ.sJsVtqm9KyUWXlKHmaTtz43rQzWeVH0ZQSpe8NVpj7A\"\n" +
" data-ad-id=\"458124646\">\n" +
" <span>Обнулить</span>" +
"<div class=\"suggesttext tleft\">\n" +
" <a href=\"#\" class=\"link clearPhoneViews\"\n" +
" data-token=\"Vtqm9KyUWXlKHmaTtz43rQzWeVH0ZQSpe8NVpj7A\"\n" +
" data-ad-id=\"2\">\n" +
" <span>Обнулить</span>";
Matcher matcher = pattern.matcher(text);
while (matcher.find()){
System.out.println(matcher.group(1));
System.out.println(matcher.group(2));
}
}
}
interface IMyListener {
public void showHtml(String html);
}
public IMyListener myListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListener = new IMyListener() {
@Override
public void showHtml(String html) {
Log.d(TAG, "showHtml: " + html);
}
};
final WebView simpleWebView=(WebView) findViewById(R.id.webview);
simpleWebView.getSettings().setJavaScriptEnabled(true);
....
}
class MyJavaScriptInterface {
public String htmlString = "";
@JavascriptInterface
public void showHTML(String html) {
htmlString = html;
Pattern p = Pattern.compile("data-sitekey=(.*?)\"><");
Matcher m = p.matcher(htmlString);
while (m.find()) {
myListener.showHtml(m.group(1));// <=================== вот здесь!
Log.d(TAG, m.group(0));
Log.d(TAG, m.group(1));
}
}
}
/стрекоза
^\/[\p{L}0-9\\s]+$
с
т
preg_match("/^\/[\стрекоза{L}0-9\\s]+$/", "/стрекоза");
preg_match("/^\/[\w{L}0-9\\s]+$/iu", "/стрекоза");
u - unicode