@marselabdullin

Как найти название исключая определенные слова в нем регулярным выражением?

Есть sql файл. В данном случае этот файл нужно воспринимать как просто текст, из которого надо вытащить строку
RV_Lnk_Document_X_PostedDocument_Purchases
:
SELECT
	ds.Document_X_PostedDocument_Purchases_DmpKey,
	ds.Document_DmpKey,
	ds.PostedDocument_DmpKey,
	ds.LoadDTM,
	ds.RecSrc,
	ds.SnapshotDT
from (
	SELECT
		hash('Document_X_PostedDocument_Purchases*' || Document_BizKey || '*' || PostedDocument_BizKey) as Document_X_PostedDocument_Purchases_DmpKey,
		hash(Document_BizKey) as Document_DmpKey,
		hash(PostedDocument_BizKey) as PostedDocument_DmpKey,
		ds.LoadDTM,
		ds.RecSrc,
		ds.SnapshotDT
	from (
		SELECT
			'Document*naCitilink*Dvs*' || cast(stg.No_ as varchar(100)) as Document_BizKey,
			'PostedDocument*naCitilink*Dvs*' || cast(stg.No_ as varchar(100)) || '*' || cast(cast(isnull(nullif(stg."Posting Date", '1753-01-01'), '1900-01-01') as timestamp) as varchar(40)) as PostedDocument_BizKey,
			'{{ macros.datetime.now() }}' as LoadDTM,
			'naCitilink*Dvs' as RecSrc,
			'{{ ds }}' as SnapshotDT
		FROM Stage.STG_Ctl_DVS_Purch__CR__Memo_Hdr_ stg
		where 
			-- catchup_snapshotdt_start
			stg.SnapshotDT = '{{ ds }}'
			-- catchup_snapshotdt_end
		and stg.No_ is not null 
		limit 1 over (partition by stg.No_, stg."Posting Date" order by "timestamp" desc)
		
	) ds
) ds

left join RawVault.PRJ_RV_Lnk_Document_X_PostedDocument_Purchases_LastValues tgt
	on tgt.Document_X_PostedDocument_Purchases_DmpKey = ds.Document_X_PostedDocument_Purchases_DmpKey
	and tgt.RecSrc = ds.RecSrc
	
where tgt.Document_X_PostedDocument_Purchases_DmpKey is NULL;


Допустим есть такая регулярка (RV.*), но она включит также этот кусочек _LastValues tgt, убрать символы можно [^], но проблема в том, что она привязывается к 1 символу, а в данном случае нужно убрать весь кусочек _LastValues tgt</code
  • Вопрос задан
  • 74 просмотра
Решения вопроса 1
@dodo512
import re

text = 'left join RawVault.PRJ_RV_Lnk_Document_X_PostedDocument_Purchases_LastValues tgt'

m = re.search('(RV\w+)_LastValues', text)

print(m.group(1))


m = re.search('RV(?:(?!_LastValues)\w)+', text)

print(m.group(0))
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы