在postgres sql中替换除ascii 32到127和ascii 0,13,27之外的所有字符

时间:2015-06-21 06:47:30

标签: sql regex postgresql greenplum

是否有任何函数可以替换除postcres sql中ascii 32到127和ascii 0,13,27之外的所有字符。我不想替换空格,换行等。我想替换像俱乐部标志,方形或奇怪的星号这样奇怪的字符。

我尝试像下面一样修改regexp_replace但它无法正常工作。

<ComboBox x:Name="FullNameComboBox" Grid.Row="1" IsEditable="True"
      ItemsSource="{Binding Path=ComboBoxItemsCollection, 
      UpdateSourceTrigger=PropertyChanged}"
      SelectedItem="{Binding SelectedItem}"
      SelectedIndex="{Binding LastValidIndex}"
      IsTextSearchEnabled="False"
      Text="{Binding CurrentFullName, UpdateSourceTrigger=LostFocus}"
      DisplayMemberPath = "FullName"
      />

非常感谢您的时间和帮助

2 个答案:

答案 0 :(得分:2)

尝试unicode范围:

select regexp_replace('abc$wanto&tore9046move#special~04 chars', '[\u0080-\u00ff]', '', 'g')

Reference

这将删除128-255 ascii范围内的任何字符。

答案 1 :(得分:1)

你几乎是对的:

select regexp_replace('abc$wanto&tore9046move#special~04 chars', '[^\x00-\x7f]', '', 'g') 

但是空字节\x00在PostgreSQL字符串文字中无效,因此您必须从\x01开始。你想要的范围从32(0x20)开始,所以使用它加上一些特定的包含13(0x0d)和27(0x1b):

select regexp_replace('abc$wanto&tore9046move#special~04 chars', '[^\x20-\x7f\x0d\x1b]', '', 'g')

或者,更有用的输入:

regress=> select regexp_replace('aáiï*∞ıb ', '[^\x20-\x7f\x0d\x1b]', '', 'g');
 regexp_replace 
----------------
 ai*b 
(1 row)