开发者

Problem with regular expression lookbehinds in javascript

开发者 https://www.devze.com 2022-12-18 18:56 出处:网络
I want to retrieve via regexp javascript figures 1 - preced开发者_开发知识库ed by either: And | or

I want to retrieve via regexp javascript figures

I thought of using lookbehind but it seems that javascript does not support lookbehind

thank you for helping me


Your description is slightly confusing. By "nothing" do you mean anything, a space, or the beginning/end of the text? I'm assuming a space.

Although look-behind would be useful, it's not strictly necessary. Couldn't you just match the whole pattern?

document.body.innerHTML.search(/(and|or)? 1/);
document.body.innerHTML.search(/2 (and|or)?/);


If you do really need lookbehind, this might get you started: http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript (and there's tons of other great stuff on there for Javascript regex, including his library, XRegExp).

0

精彩评论

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