You can use your current regex pattern (corrected as per Wiktor's comment!) by escaping the single quotes:
regexp_substr(<your string>, 'Permission:\s?''([a-zA-Z]+)''\s?Teacher name')
or more cleanly by using the alternative quoting mechanism:
regexp_substr(<your string>, q'[Permission:\s?'([a-zA-Z]+)'\s?Teacher name]')
which lets you leave the single quotes as they were originally, and put the whole thing inside a set of delimited single quotes, using a delimiter that doesn't appear in your actual content - I've used square brackets here, so q'[ ... ]'
. That lets whatever is inside, the ...
part, include unescaped single quotes.
Demos:
with t (str) as (
select q'[Time: '333333333333333333316:06:55 -232323' Permission: 'Preview' Teacher name: '4444444444444ffffffffffff' Student: 'cccccccccccssssssssss' Exam score: 'eeeeeeeeeeeA']' from dual
)
select regexp_substr(str, 'Permission:\s?''([a-zA-Z]+)''\s?Teacher name')
from t;
REGEXP_SUBSTR(STR,'PERMISSION:\S?'
----------------------------------
Permission: 'Preview' Teacher name
or:
with t (str) as (
select q'[Time: '333333333333333333316:06:55 -232323' Permission: 'Preview' Teacher name: '4444444444444ffffffffffff' Student: 'cccccccccccssssssssss' Exam score: 'eeeeeeeeeeeA']' from dual
)
select regexp_substr(str, q'[Permission:\s?'([a-zA-Z]+)'\s?Teacher name]')
from t;
REGEXP_SUBSTR(STR,Q'[PERMISSION:\S
----------------------------------
Permission: 'Preview' Teacher name
To just get the word 'Preview' you can use regexp_replace()
with a back-reference:
with t (str) as (
select q'[Time: '333333333333333333316:06:55 -232323' Permission: 'Preview' Teacher name: '4444444444444ffffffffffff' Student: 'cccccccccccssssssssss' Exam score: 'eeeeeeeeeeeA']' from dual
)
select regexp_replace(str,
'(.*Permission:\s?'')([a-zA-Z]+)(''\s?Teacher name.*)', '\2', 1, 1)
from t;
REGEXP_
-------
Preview
or
with t (str) as (
select q'[Time: '333333333333333333316:06:55 -232323' Permission: 'Preview' Teacher name: '4444444444444ffffffffffff' Student: 'cccccccccccssssssssss' Exam score: 'eeeeeeeeeeeA']' from dual
)
select regexp_replace(str,
q'[(.*Permission:\s?')([a-zA-Z]+)('\s?Teacher name.*)]', '\2', 1, 1)
from t;
REGEXP_
-------
Preview