1

I am having an extremely difficult time trying to understand why my regex is failing me at the moment. In ruby, I have a string that includes both a start and stop point, but yet I cannot grab the data in between them using regex.

finding_doc.to_s.include? finding_start
# => true
finding_doc.to_s.include? finding_stop
# => true
finding_doc.to_s[/(#{finding_start})(.*?)(#{finding_stop})/m]
# => nil

Is there any additional arguments to regex that I can provide for it to actually work? I've always seen this work for me up until now. If it has both the starting and ending points, shouldn't it be able to grab everything in between them?

It should be noted that finding_start appears before finding_stop in the finding_doc variable, as shown below:

[11] pry(#<RailsAppTest>)> finding_doc.to_s.index(finding_start)
=> 81252
[12] pry(#<RailsAppTest>)> finding_doc.to_s.index(finding_stop)
=> 192451

I should also note that the contents within finding_start and finding_stop contains a bunch of XML, so I'm not sure if any of this would have to do with anything.

Solution Attempt #1

[9] pry(#<RailsAppTest>)> finding_doc.to_s[/#{finding_start}(.*?)#{finding_stop}/m, 1]
=> nil
LewlSauce
  • 5,326
  • 8
  • 44
  • 91

0 Answers0