Reputation: 1650
For the given string,
I can haz haz bacon. Mmmm. Tasty, tasty bacon.
↑ ↑
I want to capture content bounded by the first string "az
" and the last string "as
".
In this example I cannot use ^$
anchors. I tried using:
\b(az).*(as)\b.
What am I missing?
Upvotes: 3
Views: 1235
Reputation: 250991
This would find the longest possible match:
(?<=az).*(?=as)
Demo: http://rubular.com/r/wzPdbrmbov
For shortest match:
(?<=az).*?(?=as)
Demo: http://rubular.com/r/GoPgYpGyI7
Upvotes: 3