0

I've been battling a couple things all day, and my brain is no longer functioning.

I am using this as a string "something <strong>here</strong>" and trying t ograb this out of it: <strong>here</strong>

How can I do this? I thought string.scan(/(?<=)(.*?)(=</strong>)/) would work but apparently not. Doing this in ruby btw.

LewlSauce
  • 5,326
  • 8
  • 44
  • 91
  • First, read the [mandatory disclaimer](http://stackoverflow.com/a/1732454/3764814). If you still want to use regex after that, then the simplest patten is `.*?`, but it will fail in **many** cases. – Lucas Trzesniewski Nov 29 '14 at 01:33

2 Answers2

0
<TAG\b[^>]*>(.*?)</TAG>
Robert
  • 10,126
  • 19
  • 78
  • 130
0

Is the problem that you're not escaping the slash in ?

1.9.3-p547 :012 > my_string = "something <strong>here</strong> something else <strong>another thing</strong>"
 => "something <strong>here</strong> something else <strong>another thing</strong>"
1.9.3-p547 :013 > my_string.scan(/(<strong>)(.*?)(<\/strong>)/)
 => [["<strong>", "here", "</strong>"], ["<strong>", "another thing", "</strong>"]]

Edit: This grabs it into a single element.

my_string.scan(/<strong>.*?<\/strong>/)
Johnny
  • 136
  • 3
  • Thanks. I guess this would work. It looks like my original question got a bit screwed up since I tried to insert HTML without wrapping it, but I get the point now after reading your example. Thanks – LewlSauce Nov 29 '14 at 01:38