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.

1
  • 1
    You are only capturing a single character. (\w+) will capture all the characters. Commented Nov 6, 2012 at 20:01

1 Answer 1

2

You meant to write:

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

\w captures only a single character; you want to capture all the characters until the dot. \. represents the dot, and .+ represents the rest of the line (address).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.