[解决]正则表达式字符串拆分c# [英] [Solved] regex string spliting c#

查看:146
本文介绍了[解决]正则表达式字符串拆分c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

Hi experts,

string Input = "@a = '1', @b = 'hello@123.com,hi@123.com'"



我想拆分输入字符串并希望输出如下使用正则表达式


I want to split Input string and want output as below using regex

ary[0] = a = '1'
ary[1] = b = 'hello@123.com'





我希望用@和它分开不应该用单引号

感谢adv。



I want to split by @ and it should not be in single quotes
thanks in adv.

推荐答案

不要使用正则表达式,只需使用string.Split:

Don't use a regex, just use string.Split:
string Input = "@a = '1', @b = 'hello@123.com,hi@123.com'"
string[] ary = Input.Split(',');


经过一番试验后,我得到了解决方案。错误,

希望对有相同要求的人有用

I got solution after some trial & error,
Hope it will useful for people have same requirement
string Input = "@a = '1', @b = 'hello@123.com,hi@123.com'"
string Output = Regex.Split(Input, @"(?=@\w+[ =|=])@")



(条件)true | false


(condition)true|false

(?=@\w+[ =|=]) condition 
@              if true then split by @


--condition work as below

?         In supplied input What
=         is equal to   
@\w+      a(single) word that start with @
[ =|=]    and after the word end it contain space+= or =



快乐编码!

:)


Happy Coding!
:)


访问这里..





http://www.dotnetperls.com/regex-split [ ^ ]
visit here..


http://www.dotnetperls.com/regex-split[^]


这篇关于[解决]正则表达式字符串拆分c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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