Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle regular expression replacement for negative lookahead/lookbehind

Tags:

regex

oracle

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.

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?

like image 568
Laurence Avatar asked Dec 26 '22 02:12

Laurence


1 Answers

Without lookahed and lookbehind assertions available you could try

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

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

like image 142
zerkms Avatar answered Dec 29 '22 01:12

zerkms