How to keep the Carriage Return characters in string which returned by regular expression

How can make below regular expression treat the Carriage Return (\r)
like normal character? i.e. let the “puts $1” output Who uses these
\ranyways? To escape the \r in str is one way, I’d like to know is there
a way to let regular expression just treat the \r as normal characters?

str = “Who uses these \ranyways?”
str =~ /(.*)/
puts $1

Ying Sun wrote in post #1166006:

How can make below regular expression treat the Carriage Return (\r)
like normal character? i.e. let the “puts $1” output Who uses these
\ranyways? To escape the \r in str is one way, I’d like to know is there
a way to let regular expression just treat the \r as normal characters?

str = “Who uses these \ranyways?”
str =~ /(.*)/
puts $1

On *nix it is a normal character:

irb(main):003:0> s=“Who uses these \ranyways?”
=> “Who uses these \ranyways?”
irb(main):004:0> puts s
anyways? these
=> nil
irb(main):005:0> s[/./]
=> “Who uses these \ranyways?”
irb(main):006:0> s[/.
/m]
=> “Who uses these \ranyways?”

On what platform are you? If on Windows or Mac maybe you have to use
regex option /m like I did in the last example.

Hi Robert,

Thanks for your replay, my platform is Windows7, I added /m option, but
the result still same.

Robert K. wrote in post #1166015:

Ying Sun wrote in post #1166006:

How can make below regular expression treat the Carriage Return (\r)
like normal character? i.e. let the “puts $1” output Who uses these
\ranyways? To escape the \r in str is one way, I’d like to know is there
a way to let regular expression just treat the \r as normal characters?

str = “Who uses these \ranyways?”
str =~ /(.*)/
puts $1

On *nix it is a normal character:

irb(main):003:0> s=“Who uses these \ranyways?”
=> “Who uses these \ranyways?”
irb(main):004:0> puts s
anyways? these
=> nil
irb(main):005:0> s[/./]
=> “Who uses these \ranyways?”
irb(main):006:0> s[/.
/m]
=> “Who uses these \ranyways?”

On what platform are you? If on Windows or Mac maybe you have to use
regex option /m like I did in the last example.

Robert K. wrote in post #1166218:

Ying Sun wrote in post #1166096:

Thanks for your replay, my platform is Windows7, I added /m option, but
the result still same.

Result of what and what is the result? Can you copy paste an IRB
session from the console like I did?

Hi Robert,

Sorry for the delay, IRB as below:

irb(main):001:0> str = “Who uses these \ranyways?”
=> “Who uses these \ranyways?”
irb(main):002:0> str =~ /(.*)/m
=> 0
irb(main):003:0> puts $1
anyways? these
=> nil
irb(main):004:0>

This has nothing to do with matching.

irb(main):006:0> str = “Who uses these \ranyways?”
=> “Who uses these \ranyways?”
irb(main):007:0> str =~ /(.*)/m
=> 0
irb(main):008:0> $1
=> “Who uses these \ranyways?”
irb(main):009:0> puts $1
anyways? these
=> nil

Ying Sun wrote in post #1166096:

Thanks for your replay, my platform is Windows7, I added /m option, but
the result still same.

Result of what and what is the result? Can you copy paste an IRB
session from the console like I did?