我有一个大文本,我想删除某个字符串之前的所有内容。
问题是,文本中有多次出现该字符串,我想通过稍后分析找到的文本来确定哪个是正确的。由于其复杂性,我无法将该分析包含在正则表达式中:
text = <<HERE
big big text
goes here
HERE
pos = -1
a = text.scan(/some regexp/im)
a.each do |m|
s = m[0]
# analysis of found string
...
if ( s is good ) # is the right candidate
pos = ??? # here I'd like to have a position of the found string in the text.
end
end
result_text = text[pos..-1]