简体   繁体   English

RegExp查找具有相同数字的数字

[英]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+$

Try this: 尝试这个:

^([0-9a-z])\1+$

Live demo 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式,用于删除所有空格和数字 - Regexp for removing all spaces and digits 对可能包含重复数字的数字列表进行排名 - Ranking a list of numbers that may have repeating digits POSTGRES SQL查询以查找具有一列的所有行包含格式为11位数-4位数的数字 - POSTGRES SQL query to find all the rows which have one column contains number with format like 11 digits - 4 digits 查询以获取关于发票编号具有相同日期的所有行? - Query to get all the rows that have the same date with respect to their invoice numbers? 用三位数或更多位数替换所有数字 - Replace all numbers with three digits or more 在SQL请求中,如何查找字符串的最后一部分(最后一个空格之后)中具有数字的所有记录。 - In a SQL request, how to find all the records that have digits in the last part of the string (after last whitespace) 我如何在序列中有 3 位数字的数字列(Oracle)中找到所有记录 - How would I find all records in a number column (Oracle) which have 3 digits in Sequence 如何找到所有社会保险号的后四位数相同的记录? - How can I find all the records that has the same last four digits of social security number? 数字和逗号的正则表达式 - regexp for digits AND commas SQL REGEXP - 查找包含字符串的所有用户 - SQL REGEXP - Find all users that contains string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM