English 中文(简体)
拆分字符串的复杂矩形 - Part 2
原标题:Complex regex to split up a string - Part 2

I posted this question a while back which was answered well: Complex regex to split up a string

我知道有一个新的难题 与此有关, 而且我真的没有得到任何地方...

说我现在有这样一条绳子

{foo.bar:/?a{3}}{blah}

使用上一篇文章提供的代码,它这样做:

{foo.bar:/?a
{3}}
{blah}

我希望它这样做:

{foo.bar:/?a{3}}
{blah}

这是因为现在我不得不处理在第二个卷轴前没有逃跑的线条。 我需要一些代码来识别何时可以忽略某些卷轴牙套。 例如,如果沿着从左到右的绳子阅读,它会看到第一个卷轴牙套,然后当它看到第二个卷轴牙套时,它会说,我还没有看到一个有效的卷轴牙套,所以我将忽略这一点。我理解,用纯粹的卷轴可能无法完全做到。

这是我在前一个问题中使用的代码的最初部分,

var m = str.match(/{?(\.|[^{}])+}?/g);

或者另一种解决办法是,当用户在输入 & amp; 之前提交字符串时, 它会滑入一个逃避的反斜线, 而用户看不到它。 问题在于知道谁逃避后斜线, 再次躲过用户...

最佳回答

像这样的东西呢?

var str = "{foo.bar:/?a{3}}hello?{blah}world{blah2}";

var rgx = new RegExp(/}(?!})+[^{]*{/g); 

str = str.replace(rgx,"},{");

//document.write(str + "<br/>");

arr = str.split(",");

for(i=0; i<arr.length; i++) {
    document.write(arr[i] + "<br/>");
}

这里的密钥是 regex /}(?!)+[ {}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\可以\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

字数字符匹配

(?? }) /code> 称,在上次匹配之后,至少有一个/code> 不符合要求。

[]/code> 匹配任何字符数, 不包括

字数字符匹配

看到它的工作"http://jsfiddle.net/ttKSj/6" rel="no follow">这里

问题回答

暂无回答




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...