I struggle through a complex query and need help with a REGEXP_SUBSTR command being used in the WHERE CLAUSE: In deed this are two questions.
Case 1:
SELECT REGEXP_SUBSTR('This is a sample of [192.168.178.12] containing relevant data','(?<=[ ]\[)[^\]]#]+') AS sender
SELECT REGEXP_SUBSTR('This is a sample of [dyn-192-168-178-12.example.com] containing relevant data','(?<=[ ]\[)[^\]]#]+') AS sender
SELECT REGEXP_SUBSTR('This is a sample of [only.example com] containing relevant data','(?<=[ ]\[)[^\]]#]+') AS sender
The problem above is that escaping does not work the way I've expected. Expected would be:
127.0.0.1
dyn.127.0.0.1.example.com
NULL
Case 2:
If I search in the field using the WHERE CLAUSE I have limited success with
WHERE ( sndtext RLIKE ' sender=\\<.*[0-9]{1,3}(.|-|_)[0-9]{1,3}(.|-|_)[0-9]{1,3}(.|-|_)[0-9]{1,3}.*\\>')
but the match is too broad, it needs to stop at the '>'
How can I achieve both solution in a WHERE CLAUSE?
Might not be perfekt but my solution was (less escaping):
SELECT
REGEXP_SUBSTR(msgtext, '(?<=[[])[^]]+') AS ip,
REGEXP_SUBSTR(msgtext,'(?<=[ ]sndtext=<)[^>]+') AS txt
FROM txtmessage m
WHERE msgtext RLIKE ' sndtext=<.*([0-9]{1,3}[[:punct:]]){3}[0-9]{1,3}[^>]'