[英]RegExp Find Numbers that have All Same Digits
I am working with an Oracle database and would like to write a REGEXP_LIKE expression that finds any number where all digits are the same, such as '999999999' or '777777777' without specifying the length of the field. 我正在使用Oracle数据库,并且想编写一个REGEXP_LIKE表达式来查找所有数字都相同的任何数字,例如“ 999999999”或“ 777777777”,而无需指定字段的长度。 Also, I would like it to be able to identify characters as well, such as 'aaaaa'.
另外,我希望它也能够识别字符,例如'aaaaa'。
I was able to get it working when specifying the field length, by using this: 通过使用以下命令,我可以在指定字段长度时使其工作:
select * from table1
where regexp_like (field1, '^([0-9a-z])\1\1\1\1\1\1\1\1');
But I would like it to be able to do this for any field length. 但我希望它能够在任何字段长度下都可以执行此操作。
If a field contains '7777771', for example, I would not want to see it in the results. 例如,如果一个字段包含“ 7777771”,则我不想在结果中看到它。
You're almost there. 你快到了。 You just need to anchor the end of the regex.
您只需要锚定正则表达式的末尾即可。
^([0-9a-z])\1+$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.