Escaping w/i regular expressions
Escaping w/i regular expressions
От:
Peter Eisentraut <peter@pathwaynet.com>
Дата:
How do you escape a ' (apostrophe) within a regular expression, so it does not close off the string? Something like ... ~ '[0-9.,\']' does not seem to work. (Pgsql 6.4.2) Any ideas? -- Peter Eisentraut PathWay Computing
Re: [SQL] Escaping w/i regular expressions
От:
Herouth Maoz <herouth@oumail.openu.ac.il>
Дата:
At 21:07 +0300 on 30/06/1999, Peter Eisentraut wrote: > How do you escape a ' (apostrophe) within a regular expression, so it does > not close off the string? Something like > ... ~ '[0-9.,\']' > does not seem to work. > (Pgsql 6.4.2) Yes, it does work: testing=> select * from test; nm ------------------------------------------------------- This is a regular sentence ending with a full stop. In this sentence there is a 'quoted' word. not a sentence Fi, fye, foe, fam - I smell the blood of an Englishman. There are 10,000 bottles of beer on the wall. (5 rows) testing=> select * from test where nm ~ '[0-9.,\']'; nm ------------------------------------------------------- This is a regular sentence ending with a full stop. In this sentence there is a 'quoted' word. Fi, fye, foe, fam - I smell the blood of an Englishman. There are 10,000 bottles of beer on the wall. (4 rows) See how it didn't match the 'not a sentence'? Now, to make sure, I removed the '.' from your regular expression, so the only thing to match in the 'quoted' row was the quotes: testing=> select * from test where nm ~ '[0-9,\']'; nm ------------------------------------------------------- In this sentence there is a 'quoted' word. Fi, fye, foe, fam - I smell the blood of an Englishman. There are 10,000 bottles of beer on the wall. (3 rows) Convinced? Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma
Re: [SQL] Escaping w/i regular expressions
От:
Bruce Momjian <maillist@candle.pha.pa.us>
Дата:
> How do you escape a ' (apostrophe) within a regular expression, so it does > not close off the string? Something like > ... ~ '[0-9.,\']' > does not seem to work. > (Pgsql 6.4.2) > Seems to work in 6.5: test=> select * from test where x ~ '[acb\']';x-'(1 row) -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026