使用RE进行解析? [英] Parsing using RE?

查看:97
本文介绍了使用RE进行解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello all


我需要解析一个巨大的字符串


Key< Delim1>值< Delim2>密钥< Delim1>值< Delim2>键< Delim1>

值< Delim3>


键< Delim1>值< Delim2>密钥< Delim1>值< Delim2>键< Delim1>

值< Delim3>


重复几十万次


< Delim1>分配Key,Value对

< Delim2>分成两个不同的Key,Value对

< Delim2>分隔记录。


我需要获得Key Value对并​​用一个表格填充

信息。


.NET正则表达式是否值得,以及如何以干净优化的方式进行


谢谢


-Ravi Singh

Hello all

I have a huge string that I need to parse

Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim2> Key <Delim1>
Value <Delim3>

Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim2> Key <Delim1>
Value <Delim3>

repeat for a couple hundred thousand times

The <Delim1> seprates the Key, Value pair
<Delim2> seprates two different Key,Value pairs
<Delim2> seprates records.

I need to get the Key Value pairs and populate a table with that
information.

Would the .NET regular expressions be worth while and how would I go
about doing it in a clean optimized fashion.
Thanks

-Ravi Singh

推荐答案

是的,肯定的。


你''我需要写你自己的reg exp tho


我建议使用一个名为expresso的应用程序。 free reg exp tester / builder。
http://www.ultrapico.com /Expresso.htm


如果所有分隔符都是唯一的,则肯定使用reg exp。否则,你将是

looping" while(str.indexOf("< Delim")){..."等等

使用正则表达式查找匹配会更快,并返回

数组匹配(和字段)


如果你卡住了,重新发布。


HTH

sam

Ravi Singh(UCSD)" < RA ********* @ gmail.com>在消息中写道

news:11 ********************** @ l41g2000cwc.googlegr oups.com ...
yes, definately.

you''ll need to write you own reg exp tho

i''d recommend using an app called expresso. free reg exp tester/builder.
http://www.ultrapico.com/Expresso.htm

if all the delimiters are unique definately use a reg exp. else, you''ll be
looping "while (str.indexOf("<Delim")) { ..." etc.
using regular expression to find matches would be much quicker, and return
array of matches (and fields)

if you get stuck, repost.

HTH
sam
"Ravi Singh (UCSD)" <ra*********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
大家好。

我需要解析一个巨大的字符串

Key< Delim1>值< Delim2>密钥< Delim1>值< Delim2>键< Delim1>
值< Delim3>

键< Delim1>值< Delim2>密钥< Delim1>值< Delim2>键< Delim1>
值< Delim3>

重复几十万次

< Delim1>分离Key,Value对
< Delim2>分隔两个不同的Key,Value对
< Delim2>分离记录。

我需要获取Key Value对并​​用表格填充表格。

.NET正则表达式是否值得,以及如何我会以干净优化的方式去做吗?

谢谢

-Ravi Singh
Hello all

I have a huge string that I need to parse

Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim2> Key <Delim1>
Value <Delim3>

Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim2> Key <Delim1>
Value <Delim3>

repeat for a couple hundred thousand times

The <Delim1> seprates the Key, Value pair
<Delim2> seprates two different Key,Value pairs
<Delim2> seprates records.

I need to get the Key Value pairs and populate a table with that
information.

Would the .NET regular expressions be worth while and how would I go
about doing it in a clean optimized fashion.
Thanks

-Ravi Singh



string input =" Key< Delim1>值< Delim2>密钥< Delim1>值< Delim2>

键< Delim1>值< Delim3>键< Delim1>值< Delim2>键< Delim1>

值< Delim2>密钥< Delim1>值< Delim3>" ;;


正则表达式delim1 =新正则表达式("< Delim1>");

正则表达式delim2 =新正则表达式( "< Delim2>");

Regex delim3 = new Regex("< Delim3>");


string [] rets3 = delim3.Split(输入);

string [] rets2 = delim2.Split(String.Concat(rets3));

string [] rets1 = delim1.Split( String.Concat(rets2));


rets 2和rets 1不是我所期望的。 =(。任何想法?


谢谢

-Ravi。

string input = "Key <Delim1> Value <Delim2> Key <Delim1> Value <Delim2>
Key <Delim1> Value <Delim3>Key <Delim1> Value <Delim2> Key <Delim1>
Value <Delim2> Key <Delim1> Value <Delim3>";

Regex delim1 = new Regex("<Delim1>");
Regex delim2 = new Regex("<Delim2>");
Regex delim3 = new Regex("<Delim3>");

string[] rets3 = delim3.Split(input);
string[] rets2 = delim2.Split(String.Concat(rets3));
string[] rets1 = delim1.Split(String.Concat(rets2));

rets 2 and rets 1 is not what I expect it to be. =(. any ideas?

Thanks
-Ravi.


I得到它:-)


谢谢

I got it :-)

Thanks


这篇关于使用RE进行解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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