Re: Problem with regexp

2004-02-29 Thread Paul DuBois
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]"),("");
INSERT INTO t VALUES("(OT)"),("{OT}"),("[OT]"),("");
SELECT c, c REGEXP '[[({]ot[])}]' as mtch FROM t;
Result:

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


Re: Problem with regexp

2004-02-28 Thread Ed Leafe
On Feb 28, 2004, at 10:33 AM, Michael Stassen wrote:

In the meantime, perhaps the following will help:

  mysql> select 'This is an [OT] Test'
 regexp "[ [:punct:]]OT[ [:punct:]]" as mtch;
	Hey, thanks - that works!

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://opentech.leafe.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


Re: Problem with regexp

2004-02-28 Thread Michael Stassen
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.

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?

 ___/
/
   __/
  /
 /
 Ed Leafe
Linux Love:
unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep
Unless your string column is defined as binary (or your mysql is 3.23.4 
or earlier), pattern matching is case insensitive, so you can just look 
for OT instead of [Oo][Tt].  That's not the problem here, though.

According to the manual (
and ), you have to double your 
backslashes because of the way the pattern is parsed.  I couldn't get 
that to work either, though.  Maybe after my coffee kicks in...

In the meantime, perhaps the following will help:

  mysql> select 'This is an [OT] Test'
 regexp "[ [:punct:]]OT[ [:punct:]]" as mtch;
  +--+
  | mtch |
  +--+
  |1 |
  +--+
  1 row in set (0.00 sec)
Michael

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


Problem with regexp

2004-02-28 Thread Ed Leafe
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.

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?

 ___/
/
   __/
  /
 /
 Ed Leafe
Linux Love:
unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep 

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