Re: HELP: Regex pattern matching

From: Date: Thu, 23 Jan 2003 11:44:02 +0000
Subject: Re: HELP: Regex pattern matching
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132792@lists.php.net to get a copy of this message
Hmmm... I was about to reply with a simple solution, but there's a problem with it that I can't explain. Assuming the text is in $str... I can't get preg_replace to match a newline at the end of a pattern. If I use... $str = preg_replace('/\n=.+--\n/sU', '', $str); ...it matches nothing, but if I put a tag character at the end of the dashes, e.g. --------------------------------x ...then use... $str = preg_replace('/\n=.+--x/sU', '', $str); ...it works perfectly. I'm not sure why the pattern doesn't care about the first newline, but it chokes on the second one. Any thoughts? Thanks, Alex > I have an ASCII file which has multiple blocks of text I want to clear. The > scheme is as follows: > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > line 1 Everything between the separators, > line 2 including the separators > line 3 I want to clear from the text file > line 4 > ----------------------------------------------------- > > This text I want to keep > > There are infinite number of blocks surrounded by exactly the same > separators. > So, I guess I need to clear everything between the starting "=" and the > ending "-". > > Can anyone suggest a regex pattern string that would help me accomplish > that? > > Thank you all guys in advance! > > Nasko

« previous php.general (#132792) next »