From: James Gray Date: 2008-12-02T04:37:22+09:00 Subject: Re: Regular Expressions On Dec 1, 2008, at 1:08 PM, Mmcolli00 Mom wrote: > Hi everyone. Hello. > Just a question about regualar expression in Ruby. Is there a way to > check in each line of a document for always beginning with "23430000" > and somewhere on that same line another string 'CodeRed'? Sure. > line1: 23430000 @#$#$3455000CodeRed 24AAWERE 740000000 > > This is what I have so far when I import each textdata from another > file. > > > textdata.should =~ /23430000/ |CodeRed/ textdata.should =~ /\A23430000.*CodeRed/ My changes are simple: * \A is a regex atom the only matches at the beginning of the input. I used this to make sure 23430000 is at the beginning of the line and not later. * .* matches zero or more of pretty much anything. Newlines are the only character excluded. Thus this allows anything to appear between the number and CodeRed. Now the regex above really just checks one line. If you want to check all lines, you'll want something like: textdata.each do |line| line.should =~ /\A23430000.*CodeRed/ end Hope that helps. James Edward Gray II