Reputation: 632
Dumb beginner style question but I've wrestled with this for a while now, searches result is not quite what I'm after so I'm asking you guys instead!
Given the text below I only want to extract the Id associated with the bottom line (ie 100)
<test viewId=101&somemoreStuff=999>Dont match this</test>
<test viewId=100&somemoreStuff=111>Match this</test>
so I started with something like this (regular expression):
/viewId=(.+?)&
This captures the Id for the first line but I'm after the Id of the second line so I need to include the string "Match this" to distinguish between the two, something like this (pseudo code):
/viewId=(.+?)&[ignore this section]>Match this<
Thanks!
Upvotes: 0
Views: 42
Reputation: 26667
Postive look aheads will be helpfull
viewId=(.+?)(?=&.*Match this)
(?=&.*Match this)
postive look ahead. Asserts that the viewId
is followed by Match this
Upvotes: 1
Reputation: 67968
viewId=(.+?)&[^>]*>Match this<
You can try this.See demo.
http://regex101.com/r/yR3mM3/46
Upvotes: 1