views:

52

answers:

2

Hi

I want to retrieve via regexp javascript figures

  • 1 - preceded 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

A: 

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)?/);
Chris S
A: 

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).

eyelidlessness