in reply to Regular expression..

Here's my crack at it: (adapted from something I saw regarding CPP...) I don't know ruby, but here's my best guess to what you were saying. (# to end of line. This also accounts for quotes that span multiple lines. )
#!/usr/bin/perl $/ = undef; $_ = <>; s/([^#"']*(['][^']*['])|(["][^"]*["]))|([#][^\n]*)/defined $1 ? $1 : " +"/gse; print;
Here's the input I tried.
# comment. "this is a quote" # end of line comment. print "this is a multiline quite. #right? "; No comments at all. This is just general stuff. #this is a 'test too." '
and the output was:
"this is a quote" print "this is a multiline quote. # right? "; No comments at all. This is just general stuff.
Whaddya think? (I hope i typed the code in right. I do this on a separate machine)...

Replies are listed 'Best First'.
Re^2: Regular expression..
by choroba (Cardinal) on Oct 29, 2010 at 17:10 UTC
    Is'n there something like qq() in Ruby? (Google suggests W(), %() and %%q{} and some more...) It would complicate the situation a fair bit.

      I was thinking if RUBY had Here documents, like perl does, that'd screw things up too... which doing a quick wiki search, it appears Ruby supports Here docs.

      --Ray update: of course, a regex with a # in it would also screw it up, which I imagine ruby supports too. So yeah... not a perfect solution.