Oh yes, sorry about forgetting that.
original string is
str = “xxxy”
wanted string is
str = “y”
but the x’s are not constant, the y is constant.
so another sample string can look like
str2 = “abcy”
and the wanted string from it is
str2 = “y”
So in a more human term, it is, find where y is, and then pointy
bracket whatever precedes y.
And since whatever precedes y always differs from string to string. I
would very much like to match y first, and then say " bracket all that
precedes it"
And one more thing, I read about something called the Lookahead. with
the (?=). And I could have done something like:
str = “xxxy”
re=/(.+)(?=y)/
str.gsub!(re){|s| s = “<” + s + “>”}
#=>“y”
While it worked, but in my actual string, I don’t know how I can bring
this up clearly – the string comes from the output of antiword.exe (a
program that extracts text from a word document). And in it, there
contains something like \267 or \306 which the (.+) cannot match even
if I used the u switch for UTF-8. And so I thought, maybe I should
just match y, and then manipulate whatever precedes as I originally
wanted instead of trying to match what precedes y directly.
of course if you know how to match \267, I’d be so glad to learn it,
too! And the thing is, I don’t even know what to call a “\267”. the
closest to finding a name for it, I found maybe its cousin under
Backlashes in the ruby book. But as to how to match them and what if
there’s something else in the future that pops up in the document
that’s not of this form, how will I deal with that? It’s all very
frustrating.
Thank You!