Skip to content

Instantly share code, notes, and snippets.

@ourdaidai
Last active February 2, 2021 07:35
Show Gist options
  • Save ourdaidai/2d80e6484f4482d338c715889b6fa7c3 to your computer and use it in GitHub Desktop.
Save ourdaidai/2d80e6484f4482d338c715889b6fa7c3 to your computer and use it in GitHub Desktop.
[正则表达式] #reg
匹配表注释,只保留中文英文,忽略数据字典
^[\u4e00-\u9fa5_a-zA-Z0-9]+
匹配XX_AA_XX中的 'AA'
(?<=_).*?(?=_)
# 匹配 'CREATE TABLE TEST22 SELECT uid from test1' 中的 'TEST22'
def extract_table_name(sql):
sql = re.sub(r'\s+', ' ', sql)
p_name = re.compile(r'(?<=(CREATE TABLE\s))\S+')
res = p_name.search(sql)
return res.group()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment