I have been trying to develop a regex to match a block's argument, and then all the instances of that argument.
Using this example:
File.open(inFile).each do |line|
line.chomp!
if line.empty? then
next
elsif line =~ /^>/
line.slice!(/>/)
names.push(line)
elsif line !~ /^>/
seqs.push(line)
end
end
I would like to match the word between the pipes, line
, and then all instances of line
.
Matching the argument is simple:
(?<=\|)(\w*?)(?=\|)
But I am really unsure how to use this match as a pattern for the rest of the document.
Any thoughts on how to proceed are welcome.
(Edit 2: I am now not concerned with limiting the scope of the regex to the block. I would like to match all instances in the whole document. Please consider re-examining this simpler question.)
(Edit: I am trying to incorporate this regex into a tmLanguage
file for textmate/sublime. This way, the argument and all instances are the same color. I am sure there is a way to construct a plugin to do this, but I haven't tried yet, short of looking how the sublime plugin bracketHighlighter
works.)