M
M
marselabdullin2022-03-18 11:07:30
Regular Expressions
marselabdullin, 2022-03-18 11:07:30

How to find a title excluding certain words in it with a regular expression?

There is a sql file. In this case, this file should be taken as just text from which you need to extract the line

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;


Suppose there is such a regular expression (RV.*), but it will also include this piece _LastValues tgt, you can remove the characters [^], but the problem is that it is tied to 1 character, and in this case you need to remove the entire piece_LastValues tgt</code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-03-18
@marselabdullin

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))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question