English 中文(简体)
Java: reg
原标题:JavaScript: Invalid quantifier in regex

reg是用飞机建造的,但我将其产出到火上:

(.{1,38})(+|$
?)

错误

invalid quantifier +|$
?)

我不敢确定何时开始。

实际守则是:

var re = top.RegExp;
var regex = new re("(.{1," + len + "})(+|$\n?)", "gm");

UPDATE: Per Bennor McCarthy s instructions, I changed the code to this:

 var regex = new re("(.{1," + len + "})(+|$\n?)", "gm");

消防队仍然告诉我:

invalid quantifier +|$
?)
[Break on this error] var regex = new re("(.{1," + len + "})(+|$\n?)", "gm"); 

ANOTHER UPDATE Looks Like I had to double slash it and this solved the problem!

final code

var regex = new re("(.{1," + len + "})(\+|\$\n?)", "gm");
最佳回答

问题是“+”,这是你需要越狱的证明。

而是使用:

/(.{1,38})(+|$
?)/

或在座:

"(.{1,38})(\+|$\n?)"

如果你想在字面上加上一条新线,那么你需要从<条码><>/代码>(或<条码>/在示意图内——见我最后的评论,解释。

这里有关于quantifiers 的信息。

问题回答

量化是指“多少”。 最常见的是“*”,这意味着零或更多。 “+”级表示一个或多个。

当你对非法罚款犯错误时,这几乎总是意味着你拥有一定数量的证明。 例如,由于它们意味着“多少”,它们显然必须提及一些东西。 如果你在模式或集团开始时就把自己放在一起,那么,监管机构就认为“多少?

在你的具体情况下,你在组别之后立即有一个“+”,这就是为什么你会错。 你们要么需要逃避“+”,要么没有被作为验证者对待,要么把你想要与之相匹配的某种特性或群体放在前面。 如果你试图与实际的“+”特性相匹配,这很可能是第一个。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签