不幸的是,我的正则表达式很差!你能指导我用javascript写一个正则表达式吗?它可以决定我的术语输入框。用户应该以这种格式输入术语:
#(all alphanumeric chars + blank + dash + quotation )
例如:
#keyword1#key word2#keyword3#key-word4#key word5
并且这些输入应该是非法的:
#####
##keyword1#key2#
# #keyword
#!%^&
不幸的是,我的正则表达式很差!你能指导我用javascript写一个正则表达式吗?它可以决定我的术语输入框。用户应该以这种格式输入术语:
#(all alphanumeric chars + blank + dash + quotation )
例如:
#keyword1#key word2#keyword3#key-word4#key word5
并且这些输入应该是非法的:
#####
##keyword1#key2#
# #keyword
#!%^&
/#[a-zA-Z0-9][a-zA-Z0-9 -]+/
当你说“##关键字”应该无效时,我假设你的意思是“#”应该无效,“#关键字”应该从该字符串中提取。第一个框表示关键字始终以小写字母、大写字母或数字开头。如果这太严格了,并且你想允许例如“#-keyword”,只需在第一个方括号前加上短划线,如下所示:
/#[a-zA-Z0-9-][a-zA-Z0-9 -]+/
要用javascript返回一组结果,请使用“global”修饰符(第二个斜杠后面的g)将其应用于字符串:
arrayOfKeywords = keywordString.match(/#[a-zA-Z0-9-][a-zA-Z0-9 -]+/g);
您可能希望在我的测试页。Regular-expressions.info是一个了解更多正则表达式的有用网站。它们还有一个交互式页面,用于测试上的正则表达式,这在玩游戏时很有用。
正如您所写的,术语由以下内容指定:
/#[a-zA-Z0-9 -]+/
重复该模式,并强制其包含带有^
和$
的字符串的开头和结尾。
/^(#[a-zA-Z0-9 -]+)+$/
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.
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 ...
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 ...
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 ...
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 ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
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.