簡體   English   中英

Python正則表達式-一次匹配匹配的重復模式

[英]Python Regular expression -matching repeating pattern in one shot

CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20))

我想從這個查詢字符串中獲取每個列的詳細信息(即col1小數(10,2)和col2 char(20)等)作為單個group(#anynumber)調用中的列表。 目前我在做什么如下:

columnResult = re.match(r"^CREATE(\s\w+\s*){1,}\((\w+)\s(\S+),\s*(\w+)\s(\S+)",line)
    if columnResult == None:
        pass
    else:
        print("column = ",columnResult.group(2),",",columnResult.group(4))
        print("type = ",columnResult.group(3),", ",columnResult.group(5))

而不是為每列重復(\\ w +)\\ s(\\ S +),我如何一次匹配所有重復的列詳細信息? 請幫忙

嘗試Regex: (?:(?<=, )|(?<=\\(|,))(\\w+) (\\w+)(?:\\((\\d+)(?:,(\\d+))?\\))?

演示版

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM