regex 正则表达式匹配一个单词后跟一个单词列表[重复]

polhcujo  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(90)

此问题在此处已有答案

How to match word followed by optional list of words(2个答案)
11天前关闭。
我有一个这样的Python字符串。

script = """ 
/****** Object:  Table [dbo].[AcCreditAtives]    Script Date: 7/25/2023 10:56:08 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AcCreditAtives](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ProjectId] [int] NOT NULL,
    [RegistrationId] [int] NOT NULL,
    [Image] [varbinary](max) NOT NULL,
    [Description] [nvarchar](500) NULL,
    [CreatedBy] [nvarchar](50) NOT NULL,
    [ModifiedBy] [nvarchar](50) NULL,
    [CreatedOn] [datetime] NOT NULL,
    [ModifiedOn] [datetime] NULL,
    [Status] [int] NOT NULL,
    [IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_AcCreditAtives] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[AddressInfoes]    Script Date: 7/25/2023 10:56:08 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AddressInfoes](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [BuyerId] [int] NOT NULL,
    [PermanentCountryId] [int] NULL,
    [PermanentAddressType] [int] NULL,
    [PermanentAddress] [nvarchar](60) NULL,
    [PermanentDistrict] [nvarchar](40) NULL,
    [PermanentProvince] [nvarchar](40) NULL,
    [CorrespondenceCountryId] [int] NULL,
    [CorrespondenceAddressType] [int] NULL,
    [CorrespondenceAddress] [nvarchar](60) NULL,
    [CorrespondenceDistrict] [nvarchar](40) NULL,
    [CorrespondenceProvince] [nvarchar](40) NULL,
    [CreatedOn] [datetime] NOT NULL,
    [CreatedBy] [nvarchar](255) NOT NULL,
    [ModifiedOn] [datetime] NULL,
    [ModifiedBy] [nvarchar](255) NULL,
    [Status] [int] NOT NULL,
    [IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_AddressInfo] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
"""

字符串
我想提取表名和它的列(例如表AcCreditAtives和列Id、ProjectId、...)。我已经设法用CREATE TABLE \[dbo\].\[(\w+)\]提取了表名,但无法提取列名。有没有人知道如何做到这一点?

1tu0hz3e

1tu0hz3e1#

也许是这样:

result = re.findall('\[.*NULL,',script)
for res in result:
    out = re.findall('\[.*?]',res)[0]
    print(out)

字符串
无法计算出如何“一行”它。

相关问题