开发者

Unusual regexp with javascript

开发者 https://www.devze.com 2023-02-27 12:34 出处:网络
I\'m looking for a regular expression to match a text starting with \'• To start here\' (bullet followed by a space and \"To start here\").

I'm looking for a regular expression to match a text starting with '• To start here' (bullet followed by a space and "To start here"). Does someone know how to do it ?

I keep searching and if I find the solution I'll post it.

edit (my attempt) :

var result = assert开发者_如何学编程ion.search(<li>(.To start here)</li>)

thanks,

Bruno


you're looking for the bullets in a unordered list in html, right? something like this:

<ul>
<li>To start Here</li>
<li>Another bullet</li>
</ul>

The regex for that would be:

<li>(.*?)</li>

The group '(.*?)' will catch the phrase you're looking for.

EDIT: Then what you must do to catch the phrases is:

   var regx = new RegExp('<li>(.*?)</li>');
   var result = regx.exec('<li>Hi there!</li>');
   alert (result[1]);

This will alert 'Hi there!' on the browser.

Whenever you're in doubt, try the awesome RegexPal.

cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消