[英]regular expression to read a line separated by quotation marks and semicolon
For example, I have one line of code: 例如,我有一行代码:
"12345";"ISBN345";"8"
I want to write a regular expression to extract 12345, ISBN345, 8. 我想编写一个正则表达式以提取12345,ISBN345、8。
How do I write this regular expression? 如何编写此正则表达式?
updated:sorry. 更新:对不起。
I did not make it clear. 我没有说清楚。 There are my real data :
有我的真实数据:
"276729";"052165615X";"3"
“ 276729”;“ 052165615X”;“ 3”
(my data has many lines and this line is only an example). (我的数据有很多行,而这行仅是示例)。 I want to extract
276729
(user id) as one element, 052165615X
(book number) as one, 3
(book rating) as one(that means we need to match with the regular expression three times per line,so I can create three objects each time we read one line) but not extract 276729 052165615X 3
at one time 我想将
276729
(用户ID)作为一个元素提取276729
,将052165615X
(书号)作为一个元素提取,将3
(书本评级)作为一个元素提取(这意味着我们需要每行与正则表达式匹配3次,所以我可以创建三个对象每次读取一行),但一次不提取276729 052165615X 3
Option 1: Will match and split into num, num, letters, num 选项1:将匹配并拆分为num,num,字母,num
"(\d+)";"(\d+)(.+)";"(\d+)"
Option 2: Will match and split into num, numletters, num 选项2:将匹配并拆分为num,numletters,num
"(\d+)";"(\d+.+)";"(\d+)"
"([^"]+)"(;"([^"]+)")*
[^"]+
will match a non-empty sequence of non-quote characters. You can switch +
to *
if the strings can be empty. [^"]+
将匹配非空的非引号字符序列。如果字符串可以为空,则可以将+
切换为*
。
This entire regex will a one quote sequence of not-quotes followed by zero or more quoted sequences separated by semicolons. 整个正则表达式将是一个非引号的引号序列,后跟零个或多个由分号分隔的引号序列。
I think this should do it for you. 我认为这应该为您做。
"(\\d+)";"(.*?)";"(\\d+)"
Presuming the first and third values are always numbers, and only numbers. 假定第一个和第三个值始终是数字,并且只有数字。 The second value seems like it could be anything so
.*?
第二个值似乎可以是
.*?
will allow everything to be there until the first double quote it encounters. 将允许所有内容存在,直到遇到第一个双引号为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.