At 9:42 -0500 2/28/04, Ed Leafe wrote:
Hi,

I'm trying to get a particular pattern to match, and a pattern that works in Python and other languages is not working in MySQL. I'm using 4.1.0 on RH Linux.

I archive messages from an email list, and we have a standard that posts to the list that are Off Topic should be labeled by including '[OT]' in the subject. However, some people are lazy, and type '(OT)', or '{ot}', etc. I'd like to be able to filter off-topic messages in the archives, and so a regexp that catches all these variants is what I'm looking for.

In some python scripts on the site, I use the following pattern: '[\[\(\{ ][Oo][Tt][ \]\}\)]'. That means an Open bracket/paren/brace or space, followed by 'ot' in either case, followed by a closing bracket/paren/brace or space.

Not sure why you match space above. Note that you do so both before and after the OT, but only after OT in the patterns below.


Running this in Python, I get a match:
 pat = '([\(][Oo][Tt][ \]\)])'
 tx = 'This is an (OT) Test'
 re.search(pat, tx).groups()
('(OT)',)

        But in MySQL, I don't match:
mysql> select 'This is an (OT) Test' regexp '[\(][Oo][Tt][ \]\)]' as mtch;
+------+
| mtch |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

Can anyone see the problem here?

DROP TABLE IF EXISTS t; CREATE TABLE t (c CHAR(10)); INSERT INTO t VALUES("(ot)"),("{ot}"),("[ot]"),("<ot>"); INSERT INTO t VALUES("(OT)"),("{OT}"),("[OT]"),("<OT>"); SELECT c, c REGEXP '[[({]ot[])}]' as mtch FROM t;

Result:

+------+------+
| c    | mtch |
+------+------+
| (ot) |    1 |
| {ot} |    1 |
| [ot] |    1 |
| <ot> |    0 |
| (OT) |    1 |
| {OT} |    1 |
| [OT] |    1 |
| <OT> |    0 |
+------+------+

My character classes don't have spaces in them, because I wasn't sure
about what your matching rules actually were supposed to be.

--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

MySQL Users Conference: April 14-16, 2004
http://www.mysql.com/uc2004/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to