regulare expression searches and newlines

jschmitt at vmlabs.com jschmitt at vmlabs.com
Mon Apr 24 14:28:23 EDT 2000


I guess I forgot to mention that I got it to work by not looking at the
beginning of the line.  It turns out that for my data set, not looking
for targets only at the beginning of a line was ok.

I guess if I'm running Python in Windows and I'm searching inside (I'm
assuming) a Linux or a Mac text file, Python thinks the file is just
one long line.

For the general case, the answer is to make the text files native to
your platform.

John

In article <f2TM4.3782$Za1.55405 at newsc.telia.net>,
  "Fredrik Lundh" <effbot at telia.com> wrote:
> schmitthead at my-deja.com wrote:
> > I was doing a search like this:
> >
> > searchobj = re.compile( r'^foobarbaz' )
> >
> > where I was looking for something at the beginning of a line.  This
> > works well for native text files, but not when I was searching
through
> > Linux files running on NT or NT files on Linux or some other
variation
> > because of the newline difference, I guess.  Is there any way to
handle
> > the general case?
>
> there's nothing wrong with your regular expression.
>
> I suggest printing the strings you're trying to match against,
> to see if you can figure out what's wrong.
>
> if that doesn't help, post the code.
>
> </F>
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list