Write regular expressions [closed]

I would suggest something like this: /\) (?!.*\))(\S+)/ rubular demo Or if you don’t want to have capture groups, but potentially slower: /(?<=\) )(?!.*\))\S+/ rubular demo (?!.*\)) is a negative lookahead. If what’s inside matches, then the whole match will fail. So, if .*\) matches, then the match fails, in other terms, it prevents a … Read more

How to convert Time format in ruby

You can easily do that by using the strftime method, in this case it would be something like this: Time.now.strftime(“%d/%m/%Y %H:%M”) You can find the complete docs here: http://apidock.com/ruby/DateTime/strftime

Reassigning the value of variables in Ruby?

Try something like this where you use lower case variable names rather than upper case constant names: def square_root(radicand) a, b = radicand, 1 tolerance = 0.00000000000000000001 while (a – b).abs > tolerance a = (a + b) / 2 b = radicand / a end a end print “Enter the radicand:” radicand = gets.to_f … Read more