I don't know Ruby (at all), but something similar to this should work: foo_1 foo_2". Gsub(/(foo_)(\d+)/) {|not_needed| $1 + ($2. To_i + 1).
To_s} LE: I actually made it work: codepad.org/Z5ThOvTr.
I don't know Ruby (at all), but something similar to this should work: "foo_1 foo_2". Gsub(/(foo_)(\d+)/) {|not_needed| $1 + ($2. To_i + 1).
To_s} LE: I actually made it work: codepad.org/Z5ThOvTr.
Thanks! I didn't consider matching (foo_) and reusing it in the block. – D Carney May 13 at 14:58 1 You can leave out |not_needed| entirely.
– Wayne Conrad May 13 at 18:12 @Wayne Oh, OK. But I'll leave it like that to show that it is available but not used. – Alin Purcaru May 13 at 18:18.
If you just want the numbers following foo_ to be changed str. Gsub(/(?= 1.9.
3 Actually, lookbehinds can work if your version of Ruby is >= 1.9. 1.9 adds some interesting new features and a wonderful regexp engine called Oniguruma (which is also used by PHP5 mb regex). – Thomas Hupkens May 13 at 15:18 @Phrogz. Unfortunately, most people are still using Ruby 1.8, which can handle lookahead, but not look-behind assertions… – Thomas Hupkens May 13 at 15:25 I removed my comment as I clearly don't have enough info about Ruby to make an informed comment.
Knowing that regular-expressions. Info is a reliable source I, wrongly, assumed it to be up to date. Also maybe you should add a comment in the answer to specify for what version your code works.
– Alin Purcaru May 13 at 15:49 @Phrogz For the record, the project on which I'm working is using ruby-1.8.7 (not my choice). It's an enterprise deployment with about 25 developers involved in various aspects of development and maintenance. While I'm sure all of the developers in the group would prefer ruby-1.9, there are no plans to upgrade anytime soon.
– D Carney May 13 at 15:49.
Even simpler is just using . Next "foo_1". Next #=> foo_2 "bar_1 foo_1".
Next #=> bar_1 foo_2 So, you could simplify your regex and block like so "bar_1 foo_2". Gsub(/\bfoo_\d+\b/) {|f| f. Next }.
I was wondering what the time complexity (big O) of the . Equals operator in Java was for two strings. Basically, if I did stringOne.
Equals(stringTwo) how well does this perform?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.