473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with regular expression and preg_match

I have a simple regular expression:

[0-9]{1,5}x[0-9]{1,5}

Which is designed to detect the width and height of an image from a
string, as in:

foo 100x100 bar

However, when I run this with preg_match I get an unknown modifier
error, pointing to { . Could someone please explain what I am doing
wrong and how to make this work.

preg_match("[0-9]{1,5}x[0-9]{1,5}", $output, $widthHeight);

$output is the string containing the width height values
$widthHeight is the returning array.
Many thanks.

P.s. Maximum image size is 99999x99999
Mar 21 '06 #1
2 1811
On Tue, 2006-03-21 at 20:39 +0000, splodge wrote:
I have a simple regular expression:

[0-9]{1,5}x[0-9]{1,5}

Which is designed to detect the width and height of an image from a
string, as in:

foo 100x100 bar

However, when I run this with preg_match I get an unknown modifier
error, pointing to { . Could someone please explain what I am doing
wrong and how to make this work.

preg_match("[0-9]{1,5}x[0-9]{1,5}", $output, $widthHeight);

$output is the string containing the width height values
$widthHeight is the returning array.
Many thanks.

P.s. Maximum image size is 99999x99999


Try enclosing your expression with / /.
preg_match("/[0-9]{1,5}x[0-9]{1,5}/", $output, $widthHeight);

Mar 21 '06 #2
what about the case where an image size starts with 0 (i.e. 0999x0111)
which can cause wackiness since the number will be converted to octal.
Maybe this? p.s. \d == [0-9]

preg_match("[1-9]\d{0,4}x[1-9]\d{0,4}", $output, $widthHeight);

Mar 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Eric Linders | last post by:
Hi, I'm trying to figure out the most efficient method for taking the first character in a string (which will be a number), and use it as a variable to check to see if the other numbers in the...
0
by: Moluske | last post by:
The web site was on another server i switch to a new one but this server hav now PHP Safe Mode to ON so i get error when creating thumbnail. I cant put PHP Safe mode to OFF. is ther any thing i...
4
by: TekWiz | last post by:
I'm using regex to validate data, but preg_match gives the Warning "Unknown modifier '\' " when I have '\\' in the regular expression. Is this a problem with preg_match() or do I have to do...
1
by: Stefan Reiter | last post by:
Hi, I need one function to validate streetnames and one to validate names. I tried to write my own regular expression and to use preg_match, but for some weird reason I can't get it to work. ...
3
by: Paul | last post by:
Hi, Does anyone know if it's possible to use regular expressions to grab all content between two words. For example.... ------ This is some example text to illustrate my problem and here's...
4
by: Clodoaldo Pinto | last post by:
preg_match(): Compilation failed: regular expression too large at offset 0 The regular expression is 34,745 bytes long. <?php $regExp = 'huge regexp with 34,745 bytes'; echo...
0
by: Buglish | last post by:
Hi, Task : -Capture a HTML table with use of regular expression from a text string buffer(entire document). –Pass it to another function to create a multi dimension array out of it. - Pass it...
3
by: jgentes | last post by:
Hey, I am attempting to create a random password string, and I am getting a timeout error on the regular expression. its giving me errors on the checks. line 25/27/29/31 function...
3
by: Happy Face | last post by:
Hi, All, I encountered this strange problem while using function preg_match. The following is the php code. when I set the line: $text = str_repeat('*', 12500); preg_match will return 0 for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.