이 텍스트가 포함 된 텍스트 파일이 있습니다.루비에서 두 문자열 사이에 텍스트를 가져 오는 방법은 무엇입니까?
What's New in this Version
==========================
-This is the text I want to get
-It can have 1 or many lines
-These equal signs are repeated throughout the file to separate sections
Primary Category
================
그냥 모든 것을 얻고 싶습니다. =============== = 및 Primary Category를 선택하고 해당 텍스트 블록을 변수에 저장합니다. 다음과 같은 일치 메서드가 작동 할 것이라고 생각했지만 NoMethodError : undefined method`match '
f = File.open(metadataPath, "r")
line = f.readlines
whatsNew = f.match(/==========================(.*)Primary Category/m).strip
어떤 아이디어가 있습니까? 미리 감사드립니다.
ruby regexps가 perl과 비슷한 동작을하는 경우 // m 수정자를 사용하지 않고 // 사용하고 싶습니다. \ n도 포함하십시오. // m (perl에서 적어도)은 ^와 $ match를 수정하는 방식이 다릅니다. –