正则表达式从CSV文件中读取字符串 [英] Regex to read the string from CSV file

查看:489
本文介绍了正则表达式从CSV文件中读取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要从csv文件中读取一个字符串值。



案例1:

测试人员:,UST1,


阅读UST1

案例2:

测试人员:,,


空白读取

案例3:

测试者:,UST1 UST2 UST3,


阅读UST1 UST2 UST3



我用过这个正则表达式(?< = Tester:,)(。* \。。* | \ s *)但它也读取逗号(,),

Hi,

I need to read a string value from the csv file.

Case1:
Tester:,UST1,

Read UST1
Case2:
Tester:,,

Read empty
Case3:
Tester:,UST1 UST2 UST3 ,

Read UST1 UST2 UST3

I used this regular expression (?<=Tester:,)(.*\s.*|\s*) but it reads comma(,) also

推荐答案

如何选择不是逗号的所有内容?



(?< = Tester:,)([^,] *)



您可以增强此功能以选择特定模式,只需确保每个模式中没有逗号
How about selecting out everything that isn't a comma?

(?<=Tester:,)([^,]*)

You can enhance this to select out particular patterns too, just make sure that not comma is in each pattern


这篇关于正则表达式从CSV文件中读取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆