I want to retrieve via regexp javascript figures
- 1 - preced开发者_开发知识库ed by either:
- And | or
- nothing
- 2 - followed by either:
- Nothing
- And | or
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
).
精彩评论