[英]regex to find integers in string not matching
I have two tables' contents stored in Stringbuffers. 我有两个表的内容存储在Stringbuffers中。 One has data in it; 一个里面有数据。 the other is only a header. 另一个仅是标题。 I converted the Stringbuffers into Strings and removed whitespace. 我将Stringbuffers转换为Strings并删除了空格。
table1: 表格1:
ACCOUNT_NUMBER;BRANCH_CODE;RECALC_ACTION_CODE;RECALC_DATE;PROCESS_NO;PRINCIPAL_CHG_AMXX23QRUP120970003;023;E;05.09.2013;1;-522.53 ACCOUNT_NUMBER; BRANCH_CODE; RECALC_ACTION_CODE; RECALC_DATE; PROCESS_NO; PRINCIPAL_CHG_AMXX23QRUP120970003; 023; E; 05.09.2013; 1; -522.53
table2: 表2:
ACCOUNT_NUMBER;BRANCH_CODE;MSG_TYPE ACCOUNT_NUMBER; BRANCH_CODE; MSG_TYPE
I only want to proceed with a table if it has data in it, like table1. 如果表中有数据,我只想继续处理表,例如table1。 To check for data (ie integers) I used regex: table1.matches("\\\\d")
, but this returns false. 为了检查数据(即整数),我使用了正则表达式: table1.matches("\\\\d")
,但这返回false。 I also tried table1.matches("(?s)\\\\d"))
, for new line character but even this returns false. 我也尝试使用table1.matches("(?s)\\\\d"))
换行符,但是即使返回false。
How can I check for integer data in the strings? 如何检查字符串中的整数数据?
Read the documentation on matches
. 阅读有关matches
的文档 。 The "match" requires the entire string to match, and so your table1.matches("\\\\d")
fails -- "table1" is not 'one digit only'. “匹配”要求整个字符串都匹配,因此table1.matches("\\\\d")
失败-“ table1”不是“仅一位数字”。
Use table1.matches(".*\\\\d.*")
instead. 请改用table1.matches(".*\\\\d.*")
。 Note the double backslash! 注意双反斜杠! You might not be aware they need escaping in a String constant. 您可能不知道他们需要转义String常量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.