my example is
while(line=f.gets(sep="class#{i} here will be any text "))
…
…
i+=1
end
gets() does not let you specify wild cards like * (nor a regex), so the
short answer is you can’t do what you want.
However, you could read the whole file into a variable, and then scan()
the resulting string for chunks of text that match a regex. regexes
allow all sorts of wild cards.
To come up with a regex that will read the file into the chunks you
want, post a portion of the file you want to read.
Sorry, what is this supposed to do? It looks like you are wanting to use
glob patterns in your line delimiter? I suspect this is not the best
approach to solving this problem, could you give an example of the input
file, and what values you are wanting your variable “line” to take?
It still needs to be better defined, his/her example delimiter is
"class#{i}
here will be any text ", so it isn’t correct to assume the delimiter
ends after the first digit. We really need more data, to understand what
he/she actually wants to have happen, if you throw a splat in there, it
will
eat up the rest of the string.
Another issue that could arise is if input is a large file, it could be
too
big to fit into memory, in this case, you might be able to use strscan
from
the standard library, or maybe have to find a gem to handle it, not
sure, OP
needs to give more information.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.