English 中文(简体)
j是否与植物检疫和植物检疫相同?
原标题:Is there an equivalent in jQuery to PHP s `preg_replace()`?

我有:

<img src="http://www.site.com/folder/pic.jpg">

这条道路可能毫无结果,我们基本上想把“专题......jpg作为一个变量。

我们正在这样做:

var first_img = $("#thumbnail-area li:first").find("img").attr("title");

哪套<代码> 象图像弧一样有变,但我们想做像PHP那样的先像样,以 gr取“地契”。

This has to work properly, so the path could be: folder/foo/bar/x982j/second822.jpg and it d return second822.jpg

我如何能够这样做?

最佳回答

您可使用https://developer.mozilla.org/en/Java/Reference/Global_Objects/String/replace>replace(。 http://php.net/manual/en/Function.preg-replace.php。 (也接受免费义务教育,但有一些限制,如不留人。)

str.replace(/.*//,   )

jsFiddle

或者,你可以使用......

str.split( / ).pop();

jsFiddle

问题回答

j 这里没有必要; Java文支持定期表达,因此 j格不入。

Javascript s regex取而代之的是.replace(),是舱面板上的一种方法。 您将使用以下方法:

var mystring =  this is a string ;
mystring.replace(/is a/, might be a );
//mystring is now equal to  this might be a string .

这应当足以使你开始工作。 既然你在谈到这一问题时参考了preg_replace(),我就认为你已经知道如何使用足够经常的措辞,而不必详细讨论如何解决你的具体例子。





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

热门标签