English 中文(简体)
Java
原标题:JavaScript-Regular Expressions

我说,我不是很新,经常说几句,但我迄今未能为我的问题找到适当的表述:

I want to check a string that a user types into a textfield. The string has to consist of one ore more terms that are separated with a semicolon.

实际上有两种术语:

  1. 第一类包括若干项,随后是个hy,随后是若干项,例如<代码>1-4或22-44

  2. 第二个术语包括一个编号和一个 com,重复为零或更多时间,例如1,24,5,6

All terms have to be concluded with a semicolon.

有效投入是:1-4;5,6,7;9-11;1,3;4-6;8,9,10;

我尝试了这么多的改动,但迄今无法找到解决办法。 我的问题是,这种投入可能包含任何几个术语。 我试图用<代码>OR的操作器和“lookahead”分别解决这一问题,但没有成功。

Any help would be very appreciated.

Thanks much, enne

最佳回答

该机构应做以下需要:

/^(?:[0-9]+-[0-9]+;|[0-9]+(?:,[0-9]+)*;)+$/
问题回答

EDITED: The first question looked the semicolons were separators, now it shows them as terminators.

这里的顺序为一个或多个术语,terminated/em>,由半殖民地标明,每一术语要么是编号,要么是编号,要么是编号,要么是序号,要么是编号:

/^(d+(-d+|(,d+)*)?;)+$/

With non-capturing groups

/^(?:d+(?:-d+|(?:,d+)*)?;)+$/

my take..

^(:d+--d(?: ; :d- >:d?:[,+>+”+)+





相关问题
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.