posix style regexp?

Started by Cindyover 23 years ago2 messagesgeneral
Jump to latest
#1Cindy
ctmoore@uci.edu

I've a question about escaping special characters in a ~ string operation.
To match the literal ? I would have thought I could put in \?
but this seems not to work.

Examples:
Text=# SELECT byteloc, citation FROM citations WHERE aid = 1262::smallint AND wid = 2::smallint AND citation ~ 'y"335?"z[0-9]+';
byteloc | citation
---------+----------
(0 rows)
Text=# SELECT byteloc, citation FROM citations WHERE aid = 1262::smallint AND wid = 2::smallint AND citation ~ 'y"335\?"z[0-9]+';
byteloc | citation
---------+----------
(0 rows)
Text=# SELECT byteloc, citation FROM citations WHERE aid = 1262::smallint AND wid = 2::smallint AND citation ~ 'y"335."z[0-9]+';
byteloc | citation
---------+-----------
160 | y"335?"z1
215 | y"335?"z2
276 | y"335?"z3
341 | y"335?"z4
410 | y"335?"z5
467 | y"335?"z6
530 | y"335?"z7
(7 rows)

Thanks,
--Cindy
--
ctmoore@uci.edu

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Cindy (#1)
Re: posix style regexp?

Cindy <ctmoore@uci.edu> writes:

I've a question about escaping special characters in a ~ string operation.
To match the literal ? I would have thought I could put in \?
but this seems not to work.

You need to double the backslash to get it through the string-literal
parser. Try
... citation ~ 'y"335\\?"z[0-9]+';

regards, tom lane