it-source

regexp_substr Maria가 있는 문자열에서 마지막 날짜를 추출하려면 어떻게 해야 합니까?DB

criticalcode 2023. 10. 28. 08:00
반응형

regexp_substr Maria가 있는 문자열에서 마지막 날짜를 추출하려면 어떻게 해야 합니까?DB

regexp_substr이 있는 문자열에서 마지막 날짜를 추출하려고 합니다.

어떻게 하면 되죠?

select regexp_substr('08.09.11 some text around
10.10.13 AP ab 16.10.13 some text around
13.08.2014 some text around.
01.09.2014 some text around
07.11.2014 some text. around
10.02.15 some text. around
11.02.15 some text around .  (tp)', 
'[0-9]+.[0-9]+.[0-9]+') as test

저의 실제 결과는 첫번째 날짜(08.09.11)입니다.

정말 고마워.

여기서 한 가지 방법은 사용하는 것입니다.REGEXP_REPLACE캡처 그룹과 함께:

SELECT REGEXP_REPLACE('08.09.11 some text around
10.10.13 AP ab 16.10.13 some text around
13.08.2014 some text around.
01.09.2014 some text around
07.11.2014 some text. around
10.02.15 some text. around
11.02.15 some text around .  (tp)',
'^[\\s\\S]*\\s(\\d+\.\\d+\.\\d+)[\\s\\S]*$',
'\\1') AS test

데모

다음은 사용된 regex 패턴에 대한 설명입니다.

^                       from the start of the input
    [\\s\\S]*           match all content, across newlines
    \\s                 until reaching the LAST whitespace
    (\\d+\.\\d+\.\\d+)  which is followed by the last date
                        (and capture this date in \1)
    [\\s\\S]*           consume remainder of input
$                       end of the input

언급URL : https://stackoverflow.com/questions/66105009/how-can-i-extract-last-date-from-a-string-with-regexp-substr-mariadb

반응형