Please recommend a regular expression excluding return character...

K

Kurt Euler

All-

Can anyone recommend a regular expression that excludes the return
character?

My objective is to find occurances of a string WITHIN A LINE of a text
file. Thus, if givein some_string1 and some_string2, match:

<some_string2>

Thanks!

Kurt Euler
 
D

Daniel Carrera

The '.' doesn't match newlines.

$ irb


All-

Can anyone recommend a regular expression that excludes the return
character?

My objective is to find occurances of a string WITHIN A LINE of a text
file. Thus, if givein some_string1 and some_string2, match:



Thanks!

Kurt Euler
 
R

Robert Klemme

Kurt Euler said:
All-

Can anyone recommend a regular expression that excludes the return
character?

My objective is to find occurances of a string WITHIN A LINE of a text
file. Thus, if givein some_string1 and some_string2, match:



Thanks!

Kurt Euler

If you use readline or gets you don't even need to bother with the
newlines:

File.open("file.txt", "r") do |f|
while ( line = f.gets )
line.chomp!

if /my_regexp/ =~ line
puts "Found it!"
end
end
end

Otherwise omitting the /m flag at the regexp avoids "." to match the
newline.

Regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top