[yunqa.de] Re: Regular expression in select

  • From: "Tom Holden" <ve3meo@xxxxxxxxx>
  • To: <yunqa@xxxxxxxxxxxxx>
  • Date: Thu, 16 Jun 2011 21:24:34 -0400

The regexp function only returns a 1 or 0 (true/false) just as do LIKE and GLOB. I don't see a way to use any of them to directly find part of a long string. Using substr() to iterate through the long string, one of these comparison functions can be used to find a target as in the following example:


CREATE TABLE POStable (Pos INTEGER PRIMARY KEY ASC Autoincrement);
INSERT INTO POStable Default Values; -- repeat for as long as the longest string less length of search key
CREATE TABLE stringtable (string TEXT);
INSERT INTO stringtable (string) VALUES ('onetwothree');
INSERT INTO stringtable (string) VALUES ('fourfivesix');
INSERT INTO stringtable (string) VALUES ('seveneightnine');
-- search for 'five'
SELECT MAX(pos), string FROM
(
SELECT string, pos, regexp('five.*',substr(string, pos)) AS found FROM stringtable, postable
 )
 WHERE found
;

Tom

-----Original Message----- From: D H
Sent: Thursday, June 16, 2011 10:55 AM
To: yunqa@xxxxxxxxxxxxx
Subject: [yunqa.de] Regular expression in select

Hi,

I'm using SQLiteSpy. It is a great tool !

I know that in the where clause I can use a regular expression.

Is it also possible to use a regular expression in the select clause, in
order to get only a part of a long string?
If possible, could you give a small example

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa


_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: