下面是使用regexp_replace()
的方式,應該按10g工作,假設行的格式將是相同的:
with tbl(col_string) as
(
select 'There is something 2015.06.06. in the air 1234567 242424 2015.06.07. 12125235'
from dual
)
select regexp_replace(col_string, '^.*(\d{4}\.\d{2}\.\d{2})\. \d*$', '\1')
from tbl;
正則表達式可以被解讀爲:
^ - Match the start of the line
. - followed by any character
* - followed by 0 or more of the previous character (which is any character)
( - Start a remembered group
\d{4}\.\d{2}\.\d{2} - 4 digits followed by a literal period followed by 2 digits, etc
) - End the first remembered group
\. - followed by a literal period
- followed by a space
\d* - followed by any number of digits
$ - followed by the end of the line
regexp_replace然後用第一個記憶組(\ 1)替換所有。
基本上將整行描述爲一個正則表達式,圍繞您想要返回的組進行分組。如果可能是其他字符而不是數字,你很可能需要調整行尾的正則表達式,但這應該會給你一個想法。
對於參數的緣故這部作品太ONLY IF有2次出現的日期模式:
with tbl(col_string) as
(
select 'There is something 2015.06.06. in the air 1234567 242424 2015.06.07. 12125235' from dual
)
select regexp_substr(col_string, '\d{4}\.\d{2}\.\d{2}', 1, 2)
from tbl;
返回模式的第二次出現。我期望上面的regexp_replace更準確地描述解決方案。
你能發表你試過的正則表達式嗎?這將爲回答這個問題提供一個更好的起點。 – vallismortis
select substr('There is something 2015.06.06。in the air 1234567 242424 2015.06.07。12125235',instr('There was something 2015.06.06。in the air 1234567 242424 2015.06.07。12125235',1,-1 )-instr('There is something 2015.06.06。in the air 1234567 242424 2015.06.07。12125235',regexp_substr('There was something 2015.06.06。in the air 1234567 242424 2015.06.07。12125235','\ d \ d,d,d,d,d,d),1), - 1,1),10) – Cafu90