PostgreSQL:如何在Where子句中使用RegexP?
我有一些记录,例如以下:
乌拉坦 | desc |
---|---|
1432 | aman032-枪支 |
1433 | benang156 -sikat pintu |
1434 | oli bell One at -d 20w40 |
1435 | 水refill |
1436 | kabur001 -gosok air |
1437 | kabel ties 20 cm -50, |
基于上面的桌子,我有我有两个,我有我有两个。字段中的字符串格式desc:
- 正确的格式,即Urutan 1432,1433,1436。
- 不正确的格式,即Urutan 1434,1435,1437,
如您所见,正确的格式在下面具有类似的格式:
aman032 - 枪支
然后我拆分:
[aman] [032] - [枪支]
[word] [3 digits number] [space] [ - ] [ - ] [ - ] [SPACE] [任何单词]
。
我的目标是要选择所有与POSGRESQL REGEXP在Where子句中不匹配正确格式的记录(在我不知道哪个Urutan的情况下)。因此,上表的结果是Urutan 1434,1435,1437 。
I have some records like below:
urutan | desc |
---|---|
1432 | AMAN032 - Gunting |
1433 | BENANG156 - Sikat Pintu |
1434 | Oli Bell One AT-D 20W40 |
1435 | Water Refill |
1436 | KABUR001 - Gosok Air |
1437 | Kabel Ties 20 Cm - 50 |
Based on the table above, i have two formats of string in field desc:
- the correct format, which are urutan 1432, 1433, 1436.
- the incorrect format, which are urutan 1434, 1435, 1437
as you can see, the correct format has format like this below:
AMAN032 - Gunting
then i split:
[AMAN][032] - [Gunting]
[a word][3 digits number][space][-][space][any words]
.
my goal is I want to SELECT all records which does not match the correct format using PosgreSQL REGEXP in WHERE Clause (in a condition I don't know which urutan). so the result from table above are urutan 1434, 1435, 1437.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下查询:
REGEX说明:
^
:String的启动[A-ZA-Z]+
:任何字母顺序的字符[0-9] {3 }
:三位数-
:space + dash + space[a-za-z] +
:字母字符和空格$ <$ < 的任何组合/code>:字符串的结尾
尝试在这里。
注意:此正则孔中的孔可能是字母字符的最后一个组合。您可以在提供的链接上使用它以包含您想要/不想匹配的字符,或者分享有关该部分如何组成的更多详细信息,我可以尝试改进模式匹配。
Try with the following query:
Regex Explanation:
^
: start of string[A-Za-z]+
: any alphabetical character[0-9]{3}
: three digits-
: space + dash + space[A-zA-Z ]+
: any combination of alphabetical character and space$
: end of stringTry it here.
Note: The hole in this regex may be in the last combination of alphabetical characters. You can either play with it at the provided link to include or exclude characters that you want/don't want to match for that part, or share further details on how that part can be composed of, and I could try improving the pattern matching.