0

I am not able to understand the output of following code I just wrote. I am trying to extract the complete value of the group in a string value.

>> str1 = "CREATE TABLE TABLE1 (NAME VARCHAR, PHONE VARCHAR) as SELECT NAME, PHONE FROM SCHEMA1.ADDRESS"
>> pat1 = re.compile("CREATE TABLE .+ FROM (\w).+")
>> ret= pat1.search(str1)
>> ret.groups()
('S',)

I was expecting the value to be SCHEMA1. How can I retrieve the entire value ?

Why I am doing this?

I have a file filled with DML statements intended for different schemas. So, I need to create separate files for each schema with DML statement from the file mentioned before.

4

1 回答 1

2

你的意思是写:

pat1 = re.compile("CREATE TABLE .+ FROM (\w+)\..+")

\w只捕获一个字符;你想捕获所有字符直到点。\.表示点,并.+表示线的其余部分 ( address)。

于 2012-11-06T20:02:13.967 回答