I want to fetch all the strings between _(" ") from my file.
How may i fetch that?
I want to fetch all the strings between _(" ") from my file.
How may i fetch that?
Assuming there are no quotation marks nested within the string you're looking for, you want to load the file into a string
str=File.read("/path/to/file")
Then scan the string using a regular expression. The following regular expression should do the trick. It looks for the characters _("
(the open parentheses here is escaped, because parentheses have a special meaning in regular expressions). The next parentheses starts a capturing group (so that the text of the string will be stored in the special variable $1
. Then it finds a string of consecutive characters until the first quotation mark. Then it ends the capturing group (with an unescaped close parentheses) looks for a ")
to finish the expression.
/_\("([^"]*)"\)/
To use it
str.scan( /_\("([^"]*)"\)/ ) do
puts $1
end