encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB');
headers: {
'VerificationToken': 'T1g_69b6CqBB1C0kO7XBYp_H_eVCUjnCU6GB7o3lx7VHCpSgKncivkOQuKPAxR2czgCxBb1ctnA2uK-GsIYijNH_F5Y1:Xn2ZkeeD-Ythul_Y6GxHrOcuW7bLwrUQxwf23E9hNVDPVQupoTzIdyvSch-z2-f3Ay1m8yRiISslUetKVMi3ExT1t3k1'
},
以上是一段 JavaScript 中的内容,现在要提取PublicKey
和VerificationToken
的值,也就是
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB
和
T1g_69b6CqBB1C0kO7XBYp_H_eVCUjnCU6GB7o3lx7VHCpSgKncivkOQuKPAxR2czgCxBb1ctnA2uK-GsIYijNH_F5Y1:Xn2ZkeeD-Ythul_Y6GxHrOcuW7bLwrUQxwf23E9hNVDPVQupoTzIdyvSch-z2-f3Ay1m8yRiISslUetKVMi3ExT1t3k1
正则表达式应该怎么写呢???
1
kindjeff 2016-05-04 10:43:01 +08:00 via iPhone
正则真不会~~这个直接用单引号分割字符串再取就可以呀
|
2
ZhangTingkuo OP @kindjeff 这只是网页中的一段,太长了。。
|
3
Lonely 2016-05-04 11:04:02 +08:00
encrypt\.setPublicKey\('(\w+)'\)
|
4
Lonely 2016-05-04 11:17:55 +08:00 1
headers:\s*{\s*'VerificationToken': '([-\w:_]+)'\s*}
|
5
funsunz 2016-05-04 11:28:56 +08:00
```java
String s = "encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB');\n\nheaders: {" +"\n'VerificationToken': 'T1g_69b6CqBB1C0kO7XBYp_H_eVCUjnCU6GB7o3lx7VHCpSgKncivkOQuKPAxR2czgCxBb1ctnA2uK-GsIYijNH_F5Y1:Xn2ZkeeD-Ythul_Y6GxHrOcuW7bLwrUQxwf23E9hNVDPVQupoTzIdyvSch-z2-f3Ay1m8yRiISslUetKVMi3ExT1t3k1'" +"\n},"; Matcher m = Pattern.compile("encrypt\\.setPublicKey\\(\\s*'([^']+)'.*\\s*.*VerificationToken'\\s*:\\s*'([^']+)'").matcher(s); if (m.find()){ String publicKey = m.group(1); String VerificationToken = m.group(2); System.out.println(publicKey); System.out.println(VerificationToken); } ``` |
6
funsunz 2016-05-04 11:42:48 +08:00 1
|
7
ZhangTingkuo OP @funsunz 多谢,解决了
|