English 中文(简体)
script RegEx hashtagomp #foo and #foo-fåäö, but not http://this.is/no#hashtag
原标题:javascript RegEx hashtag matching #foo and #foo-fåäö but not http://this.is/no#hashtag

Currently we re using javascript new RegExp( #[^,#=!s][^,#=!s]* ) (see [1]) and it mostly works, except that it also matches URLs with anchors like http://this。is/no#hashtag and also we d rather avoid matching foo#bar

一些尝试是用光头进行的,但似乎并没有奏效,或者我没有这样做。

来源案文如下:

#public #writable #kommentarer-till-beta -- all these should be matched
Verkligen #bra jobbat! T ex #kommentarer till #artiklar och #blogginlägg, kool。 -- mixed within text
http://this。is/no#hashtag -- problem
xxy#bar      -- We d prefer not matching this one, and。。。
#foo=bar   =foo#bar  -- we probably shouldn t match any of those either。
#foo,bar #foo;bar #foo-bar #foo:bar   -- We re flexible on whether these get matched in part or in full

我们想要达到以下产出:

(showing $ instead of <a class=tag href=。。。。。>。。。</a> for readability reasons)

$ $ $ -- all these should be matched
Verkligen $ jobbat! T ex $ till $ och $, kool。 -- mixed within text
http://this。is/no$ -- problem
xxy$      -- We d prefer not matching this one, and。。。
$=bar   =foo$  -- we probably shouldn t match any of those either。
$,bar $ $ $   -- We re flexible on whether these get matched in part or in full

[1] http://github。com/ether/pad/blob/master/etherpad/src/plugins/twitterStyleTags/hooks。js

最佳回答

我认为,寻找字面界线将在这里 do(或显然缺乏字面),这似乎与我相对应。

<编码> B#[^,#=!s]+ don t对第三行或第四行的任何改动。 然而,它符合诺福oo的 #,以及你所举的标志所涵盖的一切。

EDIT: 经过几处互换, B#[^,#=!s]+[s,]将与第一和第二行的所有内容一致。 第3-5条线和第6条线没有对应,除禁忌外,所有东西都完全吻合(只有#,巴bar在 com之前有对应关系)。

您很可能要求一个捕获组在最后离开白天或 com,以便d 成为<条码>B(#[^,#=!s]+)[s,]。

(如果你真的希望第6行的所有标签都完全吻合,将 com子从头等大类中删除)。)

请注意,你可能需要更多的东西才能完全覆盖,但这至少符合你目前的测试案例。

问题回答

暂无回答




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

热门标签