Python Regular expression -matching repeating pattern in one shot
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20))
From this query String i want to get each of the column details (ie, col1 decimal(10,2) and col2 char(20) etc ) as a list in a single group(#anynumber) call.
currently what i'am doing is given below :
columnResult = re.match(r"^CREATE(sw+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))
Instead of repeating (w+)s(S+) for each column ,how can i match all repeating column details in one shot?
Please help
python regex python-3.x
add a comment |
CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20))
From this query String i want to get each of the column details (ie, col1 decimal(10,2) and col2 char(20) etc ) as a list in a single group(#anynumber) call.
currently what i'am doing is given below :
columnResult = re.match(r"^CREATE(sw+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))
Instead of repeating (w+)s(S+) for each column ,how can i match all repeating column details in one shot?
Please help
python regex python-3.x
1
what is your exact expected outcome for the example string?
– Jean-François Fabre♦
Nov 15 '18 at 16:10
no matter how many column details are there i want them to be printed on screen.
– c0der
Nov 15 '18 at 16:13
Actually i want to print them in the following way :- column name = col1 ,type=decimal, length=10 and precision=2
– c0der
Nov 15 '18 at 16:14
add a comment |
CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20))
From this query String i want to get each of the column details (ie, col1 decimal(10,2) and col2 char(20) etc ) as a list in a single group(#anynumber) call.
currently what i'am doing is given below :
columnResult = re.match(r"^CREATE(sw+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))
Instead of repeating (w+)s(S+) for each column ,how can i match all repeating column details in one shot?
Please help
python regex python-3.x
CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20))
From this query String i want to get each of the column details (ie, col1 decimal(10,2) and col2 char(20) etc ) as a list in a single group(#anynumber) call.
currently what i'am doing is given below :
columnResult = re.match(r"^CREATE(sw+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))
Instead of repeating (w+)s(S+) for each column ,how can i match all repeating column details in one shot?
Please help
python regex python-3.x
python regex python-3.x
asked Nov 15 '18 at 16:07
c0derc0der
9591714
9591714
1
what is your exact expected outcome for the example string?
– Jean-François Fabre♦
Nov 15 '18 at 16:10
no matter how many column details are there i want them to be printed on screen.
– c0der
Nov 15 '18 at 16:13
Actually i want to print them in the following way :- column name = col1 ,type=decimal, length=10 and precision=2
– c0der
Nov 15 '18 at 16:14
add a comment |
1
what is your exact expected outcome for the example string?
– Jean-François Fabre♦
Nov 15 '18 at 16:10
no matter how many column details are there i want them to be printed on screen.
– c0der
Nov 15 '18 at 16:13
Actually i want to print them in the following way :- column name = col1 ,type=decimal, length=10 and precision=2
– c0der
Nov 15 '18 at 16:14
1
1
what is your exact expected outcome for the example string?
– Jean-François Fabre♦
Nov 15 '18 at 16:10
what is your exact expected outcome for the example string?
– Jean-François Fabre♦
Nov 15 '18 at 16:10
no matter how many column details are there i want them to be printed on screen.
– c0der
Nov 15 '18 at 16:13
no matter how many column details are there i want them to be printed on screen.
– c0der
Nov 15 '18 at 16:13
Actually i want to print them in the following way :- column name = col1 ,type=decimal, length=10 and precision=2
– c0der
Nov 15 '18 at 16:14
Actually i want to print them in the following way :- column name = col1 ,type=decimal, length=10 and precision=2
– c0der
Nov 15 '18 at 16:14
add a comment |
1 Answer
1
active
oldest
votes
Try Regex: (?:(?<=, )|(?<=(|,))(w+) (w+)(?:((d+)(?:,(d+))?))?
Demo
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323454%2fpython-regular-expression-matching-repeating-pattern-in-one-shot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try Regex: (?:(?<=, )|(?<=(|,))(w+) (w+)(?:((d+)(?:,(d+))?))?
Demo
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
add a comment |
Try Regex: (?:(?<=, )|(?<=(|,))(w+) (w+)(?:((d+)(?:,(d+))?))?
Demo
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
add a comment |
Try Regex: (?:(?<=, )|(?<=(|,))(w+) (w+)(?:((d+)(?:,(d+))?))?
Demo
Try Regex: (?:(?<=, )|(?<=(|,))(w+) (w+)(?:((d+)(?:,(d+))?))?
Demo
edited Nov 18 '18 at 12:01
answered Nov 15 '18 at 16:22
Matt.GMatt.G
2,7061416
2,7061416
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
add a comment |
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
Hi its working perfectly for CREATE TABLE IF NOT EXISTS test (col1 decimal(10,2),col2 char(20)) statements..what if the statement is like CREATE TABLE HIVE_TABLE(foo INT, bar STRING,cat INT) . ie ,without the 'if not exist' .can you please modify the regex so that it will work for both kind of statements?
– c0der
Nov 16 '18 at 8:10
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
@c0der, I've updated the regex (and demo) to handle the new requirement.
– Matt.G
Nov 16 '18 at 14:24
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
for python it is showing "(?<= A lookbehind assertion has to be fixed width ) A lookbehind assertion has to be fixed width" error
– c0der
Nov 17 '18 at 5:29
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
@c0der, updated answer for python
– Matt.G
Nov 18 '18 at 12:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323454%2fpython-regular-expression-matching-repeating-pattern-in-one-shot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
what is your exact expected outcome for the example string?
– Jean-François Fabre♦
Nov 15 '18 at 16:10
no matter how many column details are there i want them to be printed on screen.
– c0der
Nov 15 '18 at 16:13
Actually i want to print them in the following way :- column name = col1 ,type=decimal, length=10 and precision=2
– c0der
Nov 15 '18 at 16:14