84669인 학습
152542인 학습
20005인 학습
5487인 학습
7821인 학습
359900인 학습
3350인 학습
180660인 학습
48569인 학습
18603인 학습
40936인 학습
1549인 학습
1183인 학습
32909인 학습
光阴似箭催人老,日月如移越少年。
package com.company; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegExpDemo { public static void main(String[] args) { String[] data = { "interInfo.middNode(buff,\"卡号\",trade.text_借记卡号.getText());\n", "interInfo.middNode(buff,\"1234566790019\",trade.text_1234567890.getText());\n", "interInfo.middNode(buff,\"abcdefg\",trade.text_hijklmn.getText());\n", }; Pattern patternCardNumber = Pattern.compile("\"(\\w+)\"", Pattern.UNICODE_CHARACTER_CLASS); Pattern patternDebitCardNumber = Pattern.compile("trade.text_(\\w+).getText\\(\\)", Pattern.UNICODE_CHARACTER_CLASS); Matcher matcherCardNumber = null; Matcher matcherDebitCardNumber = null; for (String str: data) { matcherCardNumber = patternCardNumber.matcher(str); while (matcherCardNumber.find()) { System.out.println(matcherCardNumber.group(0)); System.out.println(matcherCardNumber.group(1)); } matcherDebitCardNumber = patternDebitCardNumber.matcher(str); while (matcherDebitCardNumber.find()) { System.out.println(matcherDebitCardNumber.group(0)); System.out.println(matcherDebitCardNumber.group(1)); } System.out.println(); } } }
output:
"卡号" 卡号 trade.text_借记卡号.getText() 借记卡号 "1234566790019" 1234566790019 trade.text_1234567890.getText() 1234567890 "abcdefg" abcdefg trade.text_hijklmn.getText() hijklmn
."(.)",trade\.(.*)\);
output:
."(.)",trade\.(.*)\);