Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4631

Ruby : Applying a function to a RegExp to retrieve its parsed form

$
0
0

Im trying to convert a Ruby file to Python using a parser.

For example parsing 'myvar.to_s' in ruby will give 'str(myvar)' in python.

In my Ruby parser I do it like this:

@line.gsub!(/(\S+)\.to_s/,'str(\1)')

using the method:

def to_s    return @lineend

Now I could like to do the same for parsing a ruby line of code that is used to match a regular expression (RegExp):

mystring =~ /myregex_(.*?)/i

This would translate in python like this :

mystring = re.search(r'myregex_(.*?)', mystring, re.IGNORECASE)

I dont know how to do this in Ruby, and Im not sure if it is even possible.


Viewing all articles
Browse latest Browse all 4631

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>