Oracle正则表达式替换,用于负向查找/向后查找 [英] Oracle regular expression replacement for negative lookahead/lookbehind

查看:156
本文介绍了Oracle正则表达式替换,用于负向查找/向后查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 PL/SQL Oracle过程,该过程在列中查找可能的客户编号.客户编号为 7位数字,并且可以带有任何数量的字符的前缀或后缀.但是,某些值包含> 7位数字,在这种情况下,我想忽略它们.因此,"A/C 1234567"和"Cust1234567B" 应返回客户编号为 1234567 的匹配项,但返回的匹配项应为" 01234567 "和" 123456789 "不应.

I'm writing a PL/SQL Oracle procedure that looks for possible customer numbers in a column. Customer numbers are 7 digits long, and could be prefixed or suffixed with any number of characters. However some of the values contain > 7 digit numbers, and in these cases I want to ignore them. So "A/C 1234567" and "Cust1234567B" should return a match for customer number 1234567, but "01234567" and "123456789" should not.

我正在使用\d{7},但是这将在所有示例上返回一个匹配项,因此我正在寻找与(?<!\d)\d{7}(?!\d)类似的内容-但不支持负向前和向后.有什么建议吗?

I am using \d{7} but this is returning a match on all the examples, so am looking for something similar to (?<!\d)\d{7}(?!\d) - but negative lookahead and lookbehind aren't supported. Any suggestions?

推荐答案

没有可用的lookahed和后向断言,您可以尝试

Without lookahed and lookbehind assertions available you could try

(^|\D)\d{7}(\D|$)

http://sqlfiddle.com/#!4/d41d8/12114/0

这篇关于Oracle正则表达式替换,用于负向查找/向后查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆