473,387 Members | 1,575 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,387 software developers and data experts.

bug in preg_match_all?

I'm reluctant to post a bug report on php.net because they're so
vicious with bogus reports, so I thought I'd check here to make sure
I'm not going crazy:

<?php
$string = "Hello[";
preg_match("/[^A-z0-9_]/", $string, $matches);
print_r($matches);
?>

Expected result:
Array(
Jun 2 '08 #1
6 1484
On May 7, 10:30*am, tommybi...@gmail.com wrote:
I'm reluctant to post a bug report on php.net because they're so
vicious with bogus reports, so I thought I'd check here to make sure
I'm not going crazy:

<?php
$string = "Hello[";
preg_match("/[^A-z0-9_]/", $string, $matches);
print_r($matches);
?>

Expected result:
Array(
Ugh, firefox...

Expected result:
Array(
[0] =[
)

Actual result:
Array(
)

PHP 5.2.4
Jun 2 '08 #2
to********@gmail.com escribió:
>$string = "Hello[";
preg_match("/[^A-z0-9_]/", $string, $matches);
Note you have 'A-z', not 'A-Z' or 'A-z'. It just happens that '[' is
between uppercase and lowercase letters.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #3
On 7 May, 15:44, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
tommybi...@gmail.com escribió:
$string = "Hello[";
preg_match("/[^A-z0-9_]/", $string, $matches);

Note you have 'A-z', not 'A-Z' or 'A-z'. It just happens that '[' is
between uppercase and lowercase letters.

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
I thik you meant to say "Note you have 'A-z', not 'A-Z' or 'a-z'."
Jun 2 '08 #4
Captain Paralytic escribió:
>>>$string = "Hello[";
preg_match("/[^A-z0-9_]/", $string, $matches);
Note you have 'A-z', not 'A-Z' or 'A-z'. It just happens that '[' is
between uppercase and lowercase letters.
I thik you meant to say "Note you have 'A-z', not 'A-Z' or 'a-z'."
Yep, sorry. I sometimes think I need a newsreader with syntax
highlighting and integrated debugger...

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #5
On May 7, 10:44 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
tommybi...@gmail.com escribió:
$string = "Hello[";
preg_match("/[^A-z0-9_]/", $string, $matches);

Note you have 'A-z', not 'A-Z' or 'A-z'. It just happens that '[' is
between uppercase and lowercase letters.

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
I tried to find a good reference for you as to why this is the case,
but nothing very good. Basically, Perl regular expressions are case
sensitive and uses ASCII character mapping, therefore [A-Z], [a-z],
and [A-z] are different. [A-Z] will allow one character from A-Z
(caps) - ASCII map numbers 65-90; [a-z] will allow one character a-z
(lowercase] - ASCII map 97-122; [A-z] goes from ASCII map 65-122
(obviously) but a little less obvious is what is between 90 and 97
(see http://en.wikipedia.org/wiki/ISO_8859-1). By using [A-z], you
are allowing all those additional characters through.

Regards,

Steve
Jun 2 '08 #6
On May 7, 11:04*am, ELINTPimp <smsi...@gmail.comwrote:
On May 7, 10:44 am, "Álvaro G. Vicario"

<alvaroNOSPAMTHA...@demogracia.comwrote:
tommybi...@gmail.com escribió:
>$string = "Hello[";
>preg_match("/[^A-z0-9_]/", $string, $matches);
Note you have 'A-z', not 'A-Z' or 'A-z'. It just happens that '[' is
between uppercase and lowercase letters.
--
--http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--

I tried to find a good reference for you as to why this is the case,
but nothing very good. *Basically, Perl regular expressions are case
sensitive and uses ASCII character mapping, therefore [A-Z], [a-z],
and [A-z] are different. *[A-Z] will allow one character from A-Z
(caps) - ASCII map numbers 65-90; [a-z] will allow one character a-z
(lowercase] - ASCII map 97-122; [A-z] goes from ASCII map 65-122
(obviously) but a little less obvious is what is between 90 and 97
(seehttp://en.wikipedia.org/wiki/ISO_8859-1). *By using [A-z], you
are allowing all those additional characters through.

Regards,

Steve
Wow, silly mistake on my part. I guess I never thought about the "A-
Z" shorthand being nothing more than an ascii character range... you
see it so frequently, and see things like [^\*-6] so rarely.

Thanks for the heads up.
Jun 2 '08 #7

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

Similar topics

4
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters...
2
by: Han | last post by:
I'm wondering if someone can explain why the following works with preg_match_all, but not preg_match: $html = "product=3456789&amp;" preg_match_all ("|product=(\d{5,10})&amp;|i", $html, $out); $out...
3
by: Han | last post by:
I know this is possible (because preg can do almost anything!), but can't get a handle on the syntax. I have an HTML string: <font size="3"><a...
5
by: Han | last post by:
Using preg_match_all, I need to capture a list of first and last names plus an optional country code proceeding them. For example: <tr><td>AU</td><td>Jane Smith</td></tr>...
2
by: Han | last post by:
The following pattern (which is one subpattern in a string of several) looks for the following $xxx,xxx.xx (with the dollar sign) or xxx,xxx.xx (space in replace of missing dollar sign) ...
0
by: petrovitch | last post by:
While using the following loop to extract images from the google search engine I discovered that preg_match_all works much faster parsing small strings in a loop than extracting all of the urls at...
10
by: greatprovider | last post by:
i'm starting with a string such as "Na**3C**6H**5O**7*2H**20" im attempting to match all **\d+ ...once i can match all the double asterix \d i intend to wrap the \d in "<sub>" tags for display...
1
by: ngmr80 | last post by:
Hi, I'm experiencing a problem when trying to capture substrings with preg_match_all() from strings like "set('Hello','World')" using the following Regular Expression (PERL syntax): ...
6
by: PaulB | last post by:
Hello, as a newbie I'm requesting some help in understanding the regular expression below preg_match_all("|<tr(.*)</tr>|U",$table,$rows); Would anybody please just run through...
2
loriann
by: loriann | last post by:
hi, I have a problem with preg_match function returning empty arrays for my wonderful regexes. However, I can't see what I am doing wrong - maybe one of you could help? I'm loading the source...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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 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.