[PHP] HELP: Regex pattern matching
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Regex pattern matching
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Regex pattern matching
Hmm... i'm not that advanced... May be first I replace any string containing --- with ---x, then use your solution? [EMAIL PROTECTED] wrote in message news:r01050400-1023-F7D646F52EC711D78B79003065B83B6C@[208.37.41.173]... 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Regex pattern matching
If the separators are always the same length, then you can use the following: $new_str = preg_replace(/(=-){5}(.*)-{10}/sU,,$str); Where 5 is how many times the =- pattern repeats, and 10 is how many times the - character repeats. Hope that helps. ---John Holmes... - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, January 23, 2003 6:44 AM Subject: Re: [PHP] HELP: Regex pattern matching 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HELP: Regex pattern matching
Thanks indeed! This pattern worked just perfect. Nasko 1lt John W. Holmes [EMAIL PROTECTED] wrote in message 00e601c2c2e0$0c204720$a629089b@TBHHCCDR">news:00e601c2c2e0$0c204720$a629089b@TBHHCCDR... If the separators are always the same length, then you can use the following: $new_str = preg_replace(/(=-){5}(.*)-{10}/sU,,$str); Where 5 is how many times the =- pattern repeats, and 10 is how many times the - character repeats. Hope that helps. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with pattern matching.
Hi, I'm looking for somebody to give me a hand to create some expressions to extract my information out of an ebay auction page. So that I can manage them more effectively. I've try lost of patterns but can't seem to get the hang of it. Is there anybody willing to lone their brain to a php newbie before my computer gets both barrels? Thanks Will