473,396 Members | 1,608 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.

Trouble with ereg() and matching right bracket "]"

I'm trying to figure out what I'm doing wrong when using ereg().

This is my regexp:

ereg("^[\]]$", "]");

and that does'n work, but this does:

ereg("^[\[]$", "[");
How come I can match left bracket but not the right?
am I using the esc char correctly?

please help me.

regards
/gange
Jul 17 '05 #1
1 2323
ga***@elak.org (Stefan Gangefors) writes:
I'm trying to figure out what I'm doing wrong when using ereg().

This is my regexp:

ereg("^[\]]$", "]");

and that does'n work, but this does:

ereg("^[\[]$", "[");

How come I can match left bracket but not the right?
am I using the esc char correctly?


The "Regular Expression Functions (POSIX Extended)" chapter of the
PHP manual directs readers to the regex manual page in the PHP
source code. That manual page says:

"To include a literal `]' in the list, make it the first character
(following a possible `^'). To include a literal `-', make it the
first or last character, or the second end- point of a range. To
use a literal `-' as the first end- point of a range, enclose it
in `[.' and `.]' to make it a collating element (see below). With
the exception of these and some combinations using `[' (see next
paragraphs), all other special characters, including `\', lose their
special significance within a bracket expression."

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #2

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

Similar topics

3
by: Evgeny Gopengauz | last post by:
What is the way recommended by Microsoft for distributing the MSSQL database with end-user application if I don't like to use sql-scripts because I need to hide the stored procedures sources (they...
1
by: Edward King | last post by:
I have a statement in a asp,like follows£º var str=window.top.main.document.all.contenttext.value; I use IIS5.0 to deploy this asp,then I visit this asp like follows:...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
44
by: Viken Karaguesian | last post by:
Hello all, On occasion I want to open hyperlinks (images, etc.) in a new window. In the past, I've used target="_blank" to open the link in a new window. However, using the "target" attribute...
1
by: tshad | last post by:
I have columns with text and radio buttons that I would like to center or put to the right of the cell, but the attribute ItemStyle-HorizontalAlign="right" doesn't seem to work. ...
4
by: lionheart | last post by:
Hi, I am currently trying to group my classes using namespaces. But since these groups are not really independend I end up to have a lot of forward declarations. My first approache was to...
5
by: Terry Olsen | last post by:
This is the easiest way I can think of to do this: tmp=Right("0" & Now.Month.ToString, 2) The only way I've figured to do it the .NET way is this: tmp="0" & Now.Month.ToString...
8
by: Chaitanya | last post by:
Hello, In my Application i want to know when user clicks both the "Left" and "Right" buttons of the Mouse. I am getting a number like this "3145728". But the MouseButtons Enum contains only Left,...
8
by: rssd | last post by:
can somebody help me. I'm trying to read some excel files but i'm always getting this error No type library matching "Microsoft Excel" found at D:\Genes_datasets\exp.pl line 4 Win32::OLE(0.16):...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.