I won't say much nonsense, let's just read the code~
Example
imos=# select 'hello' ~ '[\u2e80-\ua4cf]|[\uf900-\ufaff]|[\ufe30-\ufe4f]'; ?column? ---------- f (1 row) imos=# imos=# select 'helloChina' ~ '[\u2e80-\ua4cf]|[\uf900-\ufaff]|[\ufe30-\ufe4f]'; ?column? ---------- t (1 row)
Supplement: Several methods of postgreSQL to determine the content of strings
Several ways to determine the content of a string:
1. position(substring in string):
postgres=# select position('aa' in 'abcd'); position ---------- 0 (1 row) postgres=# select position('ab' in 'abcd'); position ---------- 1 (1 row) postgres=# select position('ab' in 'abcdab'); position ---------- 1 (1 row)
It can be seen that if the target string is included, it will return the location where the target string first appears. You can judge whether the target string is included based on whether the return value is greater than 0.
2. strpos(string, substring):
The function of this function is to declare the position of the substring.
postgres=# select strpos('abcd','aa'); strpos -------- 0 (1 row) postgres=# select strpos('abcd','ab'); strpos -------- 1 (1 row) postgres=# select strpos('abcdab','ab'); strpos -------- 1 (1 row)
The function is consistent with the position function.
3. Use regular expressions:
postgres=# select 'abcd' ~ 'aa'; ?column? ---------- f (1 row) postgres=# select 'abcd' ~ 'ab'; ?column? ---------- t (1 row) postgres=# select 'abcdab' ~ 'ab'; ?column? ---------- t (1 row)
4. Use the @> operator of the array (cannot accurately determine whether it contains):
postgres=# select regexp_split_to_array('abcd','') @> array['b','e']; ?column? ---------- f (1 row) postgres=# select regexp_split_to_array('abcd','') @> array['a','b']; ?column? ---------- t (1 row)
Note the following examples:
postgres=# select regexp_split_to_array('abcd','') @> array['a','a']; ?column? ---------- t (1 row) postgres=# select regexp_split_to_array('abcd','') @> array['a','c']; ?column? ---------- t (1 row) postgres=# select regexp_split_to_array('abcd','') @> array['a','c','a','c']; ?column? ---------- t (1 row)
It can be seen that when judging the operator containing the array, regardless of order or repetition, it will return true as long as it is included, and pay attention to it when it is actually used.
The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.