Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex PostgreSQL查找字符串中包含精确字符串的位置_Regex_Postgresql - Fatal编程技术网

Regex PostgreSQL查找字符串中包含精确字符串的位置

Regex PostgreSQL查找字符串中包含精确字符串的位置,regex,postgresql,Regex,Postgresql,我有一个表,其值如下: “人力资源总监” “管理层的协助” 如果我有像“hr”这样的字符串,我想找到“headofhr”行。 简单的“LIKE%hr%”不够精确,因为还会找到其他包含“hr”字符串的行。 我想我需要一些正则表达式 也许有人能给我一个提示,怎么写 谢谢 Alex使用 WHERE col ~ '\yHR\y' \yHR\y正则表达式将匹配整个单词的HR(\y是单词边界,它匹配单词的开头或结尾) : 结果: CREATE TABLE tabl1 (s character

我有一个表,其值如下:

  • “人力资源总监”
  • “管理层的协助”
如果我有像“hr”这样的字符串,我想找到“headofhr”行。 简单的“LIKE%hr%”不够精确,因为还会找到其他包含“hr”字符串的行。 我想我需要一些正则表达式

也许有人能给我一个提示,怎么写

谢谢 Alex使用

WHERE col ~ '\yHR\y'
\yHR\y
正则表达式将匹配整个单词的
HR
\y
是单词边界,它匹配单词的开头或结尾)

:

结果:

CREATE TABLE tabl1
    (s character varying)
;

INSERT INTO tabl1
    (s)
VALUES
    ('Head of HR'),
    ('Assistance of management'),
    ('CHROME')
;

select * from tabl1 where s ~ '\yHR\y';