Say I have the following script:
<?php
$contents = file_get_contents('preg_test.txt');
echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt: http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Any ideas as to why it doesn't? 7 1395
yawnmoth <te*******@yahoo.comwrote:
Say I have the following script:
<?php
$contents = file_get_contents('preg_test.txt');
echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Hmmmz, they both match here in PHP 5.1.4, PCRE Library Version 6.6
06-Feb-2006, with or without the modifier. What version are you using?
--
Rik Wasmus
On Feb 5, 2:13 pm, Rik <luiheidsgoe...@hotmail.comwrote:
yawnmoth<terra1...@yahoo.comwrote:
Say I have the following script:
<?php
$contents = file_get_contents('preg_test.txt');
echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Hmmmz, they both match here in PHP 5.1.4, PCRE Library Version 6.6
06-Feb-2006, with or without the modifier. What version are you using?
PHP 5.2.0 (cli).
yawnmoth <te*******@yahoo.comwrote:
On Feb 5, 2:13 pm, Rik <luiheidsgoe...@hotmail.comwrote:
>yawnmoth<terra1...@yahoo.comwrote:
Say I have the following script:
<?php
$contents = file_get_contents('preg_test.txt');
echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
>http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Hmmmz, they both match here in PHP 5.1.4, PCRE Library Version 6.6 06-Feb-2006, with or without the modifier. What version are you using?
PHP 5.2.0 (cli).
Hmmmz, the file you gave was the actual file you tested it with, or justa
part of it? Might be it just maxes out. I really don't have any other
ideas :(
--
Rik Wasmus
On Mon, 05 Feb 2007 11:24:30 -0800, yawnmoth <te*******@yahoo.comwrote:
Say I have the following script:
<?php
$contents = file_get_contents('preg_test.txt');
echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Any ideas as to why it doesn't?
This is a very inefficient regex for a large amount of data. Since you are
using the lazy asterisk with the dot, the regex engine immediately starts
backtracking throughout the search. It would be easier to specify the
amount of d's through the {} quantifier, not hardcoding.
Is there a reason you capture all the content before the CRLF and d
portion of the pattern? It looks like you're merely testing if any
whitespace and 13 d's exist. If that's the case, you could just use the
strstr() function. If you want everything except the whitespace and d's,
then use substr().
--
Curtis, http://dyersweb.com
On Feb 5, 4:03 pm, Rik <luiheidsgoe...@hotmail.comwrote:
yawnmoth<terra1...@yahoo.comwrote:
On Feb 5, 2:13 pm, Rik <luiheidsgoe...@hotmail.comwrote:
<snip>
Hmmmz, the file you gave was the actual file you tested it with, or just a
part of it? Might be it just maxes out. I really don't have any other
ideas :(
Yup - that's the actual file. In testing similar files, I noted that
removing a few characters from the middle made it work just fine.
This made me think that it was maxing out, but then I tried to write a
PHP script to sorta auto-generate a more simplified file that'd
demonstrate the problem but was unable to do so.
On Feb 7, 2:50 am, Curtis <dyers...@verizon.netwrote:
On Mon, 05 Feb 2007 11:24:30 -0800,yawnmoth<terra1...@yahoo.comwrote:
Say I have the following script:
<?php
$contents = file_get_contents('preg_test.txt');
echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is
equal' : 'is not equal';
?>
Here's preg_test.txt:
http://www.geocities.com/terra1024/preg_test.txt
(it's a malformed part of a postscript file, in case you're curious)
My question is... when I remove the s modifier, preg_match returns
true. When the s modifier is there, it returns false. I'm not really
sure why this is. The s modifier means that . includes new lines and
carriage returns. In either case, it seems like it should match.
Any ideas as to why it doesn't?
This is a very inefficient regex for a large amount of data. Since you are
using the lazy asterisk with the dot, the regex engine immediately starts
backtracking throughout the search. It would be easier to specify the
amount of d's through the {} quantifier, not hardcoding.
Is there a reason you capture all the content before the CRLF and d
portion of the pattern? It looks like you're merely testing if any
whitespace and 13 d's exist. If that's the case, you could just use the
strstr() function. If you want everything except the whitespace and d's,
then use substr().
I'm trying to extract fonts from *.ps files. Because the fonts can
have any name of any length (afaik), substr() isn't sufficient. That
said, I assume [^\r\n]+ would be more efficient than .*? ?
yawnmoth wrote:
On Feb 7, 2:50 am, Curtis <dyers...@verizon.netwrote:
>On Mon, 05 Feb 2007 11:24:30 -0800,yawnmoth<terra1...@yahoo.comwrote:
>>Say I have the following script: <?php $contents = file_get_contents('preg_test.txt'); echo preg_match("#(.*?)[\r\n]+ddddddddddddd#s",$contents) ? 'is equal' : 'is not equal'; ?> Here's preg_test.txt: http://www.geocities.com/terra1024/preg_test.txt (it's a malformed part of a postscript file, in case you're curious) My question is... when I remove the s modifier, preg_match returns true. When the s modifier is there, it returns false. I'm not really sure why this is. The s modifier means that . includes new lines and carriage returns. In either case, it seems like it should match. Any ideas as to why it doesn't?
This is a very inefficient regex for a large amount of data. Since you are using the lazy asterisk with the dot, the regex engine immediately starts backtracking throughout the search. It would be easier to specify the amount of d's through the {} quantifier, not hardcoding.
Is there a reason you capture all the content before the CRLF and d portion of the pattern? It looks like you're merely testing if any whitespace and 13 d's exist. If that's the case, you could just use the strstr() function. If you want everything except the whitespace and d's, then use substr().
I'm trying to extract fonts from *.ps files. Because the fonts can
have any name of any length (afaik), substr() isn't sufficient. That
said, I assume [^\r\n]+ would be more efficient than .*? ?
Yeah [^\r\n]+ is definitely more efficient, as it won't cause
backtracking.
--
Curtis, http://dyersweb.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Max |
last post by:
Hi,
I'm a perl programmer and am trying to learn PHP.
So far I have figured out most of the differences, but have not been able to
find out how to do the following:
When running through a...
|
by: Sisnaz |
last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for
the life of me I can't figure out.
I placed a menu navigation componet on my master page and defined the
navigation...
|
by: JoeC |
last post by:
I am writing a program and I would like to pass an array of objects to
a function and from that object I want to return a valuse to that
function how do I do it?
Here is what I have:
terrain...
|
by: Mark Huebner |
last post by:
If I have a class C that contains a private variable (property) V and
private function T and T is executed within C as a separate thread, does
thread T have access to private variable (property) V...
|
by: =?ISO-8859-1?Q?Feij=F3?= |
last post by:
I'm very new to Regex, I've been strugling a lot to use it, hard to
find good material :)
I just need to find all matchs for something like this:
D00:00:00:00
leter D, following by 4...
| |
by: WebCM |
last post by:
There are lots of problems with XHTML parsing in PHP by XML functions.
I've just solved most of them. However, how to get value of attribute
with namespace?
<input type="checkbox" id="something"...
|
by: Sudhakar |
last post by:
A) validating username in php
as part of a registration form a user fills there desired username and
this is stored in a mysql. there are certain conditions for the
username.
a) the username...
|
by: Jeff |
last post by:
I'm parsing this:
name="value"
and sometimes it looks like this:
name2="value2
without the closing '"'. I don't want to capture the end quote.
|
by: Daniel |
last post by:
Hello,
It was my understanding that when the PCRE module was loaded in php
that constants would be available that were built in to that module.
For example, I need to use some flags with my...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |