How do I create a regex for ipaddress to be used with other patterns in PL SQL
I need to write a regular expression in order to be able to match the following patterns:
IF:en0
IF:en0:10.94.80.78
IF:en11
IF:en11:10.94.80.78
The regular expression i wrote in 开发者_StackOverflow中文版PL SQL was
IF REGEXP_LIKE(input_str,
'^IF:en([0-9])([:]?)((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})$') then
DBMS_OUTPUT.PUT_LINE('Match');
END IF;
This works fine. But I want to know if there is a way in which I can make the pattern for ip address
((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})
as a variable above and use something like
ipaddrpattern :=
'((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})';
IF REGEXP_LIKE(input_str,
'^IF:en([0-9])([:]?)||ipaddrpattern||$') then
DBMS_OUTPUT.PUT_LINE('Match');
END IF;
I tried the above but didn't work. Can someone please help me with the syntax?
You might want to concatenate your pattern :)
Use
'^IF:en([0-9])([:]?)' || ipaddrpattern || '$') then
instead of
'^IF:en([0-9])([:]?)||ipaddrpattern||$') then
Your current implementation would match
'IF:en1ipaddrpattern'
精彩评论