regex find substring and replace characters and update whole string
From
string= this is, not good "type of ,question" to ask, on stackoverflow
I want to extract "type of , question"
substring and replace ','
with ' '
.
with re.findall()
it yields a list of characters between " "
and with re.search
it yields class object.
With re.sub()
it replaces all ','
but I need them except the ones that are inside sub-string with double quotes.
Can anyone help me with this problem.
Thanks in advance!!
python regex
|
show 4 more comments
From
string= this is, not good "type of ,question" to ask, on stackoverflow
I want to extract "type of , question"
substring and replace ','
with ' '
.
with re.findall()
it yields a list of characters between " "
and with re.search
it yields class object.
With re.sub()
it replaces all ','
but I need them except the ones that are inside sub-string with double quotes.
Can anyone help me with this problem.
Thanks in advance!!
python regex
It sounds like you already tried usingre.findall
,re.search
, andre.sub
, yes? Please share the code for each of those attempts.
– Kevin
Nov 20 at 16:27
output: this is, not good "type of question" to ask, on stackoverflow
– Devanshu Khokhani
Nov 20 at 16:27
Is it'string= this is, not good "type of ,question" to ask, on stackoverflow'
orstring = 'this is, not good "type of ,question" to ask, on stackoverflow'
?
– Daniel F
Nov 20 at 16:29
What should happen if there are more than two quote marks in the string? What if there are an odd number of quote marks? What if there are two 'real' quote marks, and one escaped quote mark inside that quote?
– Kevin
Nov 20 at 16:29
1
If the only data the code needs to work on is the one example you gave, then you only have to doresult = 'this is, not good "type of question" to ask, on stackoverflow'
. If you're thinking "very funny, I actually need it to work on a variety of inputs", then that's exactly why I'm asking these clarifying questions :-)
– Kevin
Nov 20 at 16:33
|
show 4 more comments
From
string= this is, not good "type of ,question" to ask, on stackoverflow
I want to extract "type of , question"
substring and replace ','
with ' '
.
with re.findall()
it yields a list of characters between " "
and with re.search
it yields class object.
With re.sub()
it replaces all ','
but I need them except the ones that are inside sub-string with double quotes.
Can anyone help me with this problem.
Thanks in advance!!
python regex
From
string= this is, not good "type of ,question" to ask, on stackoverflow
I want to extract "type of , question"
substring and replace ','
with ' '
.
with re.findall()
it yields a list of characters between " "
and with re.search
it yields class object.
With re.sub()
it replaces all ','
but I need them except the ones that are inside sub-string with double quotes.
Can anyone help me with this problem.
Thanks in advance!!
python regex
python regex
edited Nov 20 at 16:23
anubhava
519k46316389
519k46316389
asked Nov 20 at 16:20
Devanshu Khokhani
428
428
It sounds like you already tried usingre.findall
,re.search
, andre.sub
, yes? Please share the code for each of those attempts.
– Kevin
Nov 20 at 16:27
output: this is, not good "type of question" to ask, on stackoverflow
– Devanshu Khokhani
Nov 20 at 16:27
Is it'string= this is, not good "type of ,question" to ask, on stackoverflow'
orstring = 'this is, not good "type of ,question" to ask, on stackoverflow'
?
– Daniel F
Nov 20 at 16:29
What should happen if there are more than two quote marks in the string? What if there are an odd number of quote marks? What if there are two 'real' quote marks, and one escaped quote mark inside that quote?
– Kevin
Nov 20 at 16:29
1
If the only data the code needs to work on is the one example you gave, then you only have to doresult = 'this is, not good "type of question" to ask, on stackoverflow'
. If you're thinking "very funny, I actually need it to work on a variety of inputs", then that's exactly why I'm asking these clarifying questions :-)
– Kevin
Nov 20 at 16:33
|
show 4 more comments
It sounds like you already tried usingre.findall
,re.search
, andre.sub
, yes? Please share the code for each of those attempts.
– Kevin
Nov 20 at 16:27
output: this is, not good "type of question" to ask, on stackoverflow
– Devanshu Khokhani
Nov 20 at 16:27
Is it'string= this is, not good "type of ,question" to ask, on stackoverflow'
orstring = 'this is, not good "type of ,question" to ask, on stackoverflow'
?
– Daniel F
Nov 20 at 16:29
What should happen if there are more than two quote marks in the string? What if there are an odd number of quote marks? What if there are two 'real' quote marks, and one escaped quote mark inside that quote?
– Kevin
Nov 20 at 16:29
1
If the only data the code needs to work on is the one example you gave, then you only have to doresult = 'this is, not good "type of question" to ask, on stackoverflow'
. If you're thinking "very funny, I actually need it to work on a variety of inputs", then that's exactly why I'm asking these clarifying questions :-)
– Kevin
Nov 20 at 16:33
It sounds like you already tried using
re.findall
, re.search
, and re.sub
, yes? Please share the code for each of those attempts.– Kevin
Nov 20 at 16:27
It sounds like you already tried using
re.findall
, re.search
, and re.sub
, yes? Please share the code for each of those attempts.– Kevin
Nov 20 at 16:27
output: this is, not good "type of question" to ask, on stackoverflow
– Devanshu Khokhani
Nov 20 at 16:27
output: this is, not good "type of question" to ask, on stackoverflow
– Devanshu Khokhani
Nov 20 at 16:27
Is it
'string= this is, not good "type of ,question" to ask, on stackoverflow'
or string = 'this is, not good "type of ,question" to ask, on stackoverflow'
?– Daniel F
Nov 20 at 16:29
Is it
'string= this is, not good "type of ,question" to ask, on stackoverflow'
or string = 'this is, not good "type of ,question" to ask, on stackoverflow'
?– Daniel F
Nov 20 at 16:29
What should happen if there are more than two quote marks in the string? What if there are an odd number of quote marks? What if there are two 'real' quote marks, and one escaped quote mark inside that quote?
– Kevin
Nov 20 at 16:29
What should happen if there are more than two quote marks in the string? What if there are an odd number of quote marks? What if there are two 'real' quote marks, and one escaped quote mark inside that quote?
– Kevin
Nov 20 at 16:29
1
1
If the only data the code needs to work on is the one example you gave, then you only have to do
result = 'this is, not good "type of question" to ask, on stackoverflow'
. If you're thinking "very funny, I actually need it to work on a variety of inputs", then that's exactly why I'm asking these clarifying questions :-)– Kevin
Nov 20 at 16:33
If the only data the code needs to work on is the one example you gave, then you only have to do
result = 'this is, not good "type of question" to ask, on stackoverflow'
. If you're thinking "very funny, I actually need it to work on a variety of inputs", then that's exactly why I'm asking these clarifying questions :-)– Kevin
Nov 20 at 16:33
|
show 4 more comments
5 Answers
5
active
oldest
votes
Use regex capture groups:
import re
s= 'this is, not good "type of ,question" to ask, on stackoverflow'
re.sub(r'(".*?),(.*?")', r'12', s)
output:
'this is, not good "type of question" to ask, on stackoverflow'
Explanation: (stuff)
in regex stands for capture groups, 1
and 2
respectively substitutes the part before and after the ,
character within the quoted part of string. Please note this also works for multiple quotes within a single string as well.
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Very nice. In order to add the space (from the requirementreplace ',' with ' '
), add a space between1
and2
– Daniel F
Nov 20 at 16:53
1
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
Also unbalanced quotes will introduced problems. See'this is, not good", "type of ,question" to ask, on stackoverflow'
yieldsthis is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
|
show 1 more comment
Another way that gives you some flexibility is you can do it by two steps:
Find all the matches that are contained in quotations,
In each match look for and replace the
','
.
Example:
# define a pattern that gets you everything inside a double quote
pat = re.compile(r'"[^"]+"')
# re.sub the quote pattern and replace the , in each of those matches.
string = pat.sub(lambda x: x.group(0).replace(',',''), string)
# 'this is, not good "type of question" to ask, on stackoverflow'
The flexibility of this is it allows you to replace as many ','
as you need, and you can perform other changes as well once you have located all the double quote patterns.
This should be higher up. My solution does not address multiple,
in a single quote, which is a big overlook on my part.
– Rocky Li
Nov 20 at 17:14
add a comment |
How about a combination of split()
and replace()
? :
s = 'this is, not good "type of ,question" to ask, on stackoverflow'
splitted = s.split('"')
print(s.replace(splitted[1], splitted[1].replace(',', '')))
# this is, not good "type of question" to ask, on stackoverflow
Note: This works in this case, but does not work in cases where you have the exact same string within double quotes outside the double quotes.
add a comment |
How about this:
b=""" "hello, howdy". sample text, text then comes "Another, double, quotes" """
for str_match in re.findall(r"".*?"",b):
b = re.sub(str_match,re.sub(r","," ",str_match),b)
print(b)
output: "hello howdy". sample text, text then comes "Another double quotes" '
add a comment |
I'm not completely sure if this will match all your requirements, but on the template you offer the following would return what you are looking for.
result = re.sub('("(?:[^"])*),((?:[^"])*")', r"1 2")
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
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%2f53397243%2fregex-find-substring-and-replace-characters-and-update-whole-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use regex capture groups:
import re
s= 'this is, not good "type of ,question" to ask, on stackoverflow'
re.sub(r'(".*?),(.*?")', r'12', s)
output:
'this is, not good "type of question" to ask, on stackoverflow'
Explanation: (stuff)
in regex stands for capture groups, 1
and 2
respectively substitutes the part before and after the ,
character within the quoted part of string. Please note this also works for multiple quotes within a single string as well.
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Very nice. In order to add the space (from the requirementreplace ',' with ' '
), add a space between1
and2
– Daniel F
Nov 20 at 16:53
1
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
Also unbalanced quotes will introduced problems. See'this is, not good", "type of ,question" to ask, on stackoverflow'
yieldsthis is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
|
show 1 more comment
Use regex capture groups:
import re
s= 'this is, not good "type of ,question" to ask, on stackoverflow'
re.sub(r'(".*?),(.*?")', r'12', s)
output:
'this is, not good "type of question" to ask, on stackoverflow'
Explanation: (stuff)
in regex stands for capture groups, 1
and 2
respectively substitutes the part before and after the ,
character within the quoted part of string. Please note this also works for multiple quotes within a single string as well.
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Very nice. In order to add the space (from the requirementreplace ',' with ' '
), add a space between1
and2
– Daniel F
Nov 20 at 16:53
1
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
Also unbalanced quotes will introduced problems. See'this is, not good", "type of ,question" to ask, on stackoverflow'
yieldsthis is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
|
show 1 more comment
Use regex capture groups:
import re
s= 'this is, not good "type of ,question" to ask, on stackoverflow'
re.sub(r'(".*?),(.*?")', r'12', s)
output:
'this is, not good "type of question" to ask, on stackoverflow'
Explanation: (stuff)
in regex stands for capture groups, 1
and 2
respectively substitutes the part before and after the ,
character within the quoted part of string. Please note this also works for multiple quotes within a single string as well.
Use regex capture groups:
import re
s= 'this is, not good "type of ,question" to ask, on stackoverflow'
re.sub(r'(".*?),(.*?")', r'12', s)
output:
'this is, not good "type of question" to ask, on stackoverflow'
Explanation: (stuff)
in regex stands for capture groups, 1
and 2
respectively substitutes the part before and after the ,
character within the quoted part of string. Please note this also works for multiple quotes within a single string as well.
edited Nov 20 at 16:39
answered Nov 20 at 16:29
Rocky Li
2,8101316
2,8101316
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Very nice. In order to add the space (from the requirementreplace ',' with ' '
), add a space between1
and2
– Daniel F
Nov 20 at 16:53
1
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
Also unbalanced quotes will introduced problems. See'this is, not good", "type of ,question" to ask, on stackoverflow'
yieldsthis is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
|
show 1 more comment
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Very nice. In order to add the space (from the requirementreplace ',' with ' '
), add a space between1
and2
– Daniel F
Nov 20 at 16:53
1
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
Also unbalanced quotes will introduced problems. See'this is, not good", "type of ,question" to ask, on stackoverflow'
yieldsthis is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
this one worked perfectly for me. Thanks for helping me out @Rocky Li
– Devanshu Khokhani
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Glad to be able to help
– Rocky Li
Nov 20 at 16:34
Very nice. In order to add the space (from the requirement
replace ',' with ' '
), add a space between 1
and 2
– Daniel F
Nov 20 at 16:53
Very nice. In order to add the space (from the requirement
replace ',' with ' '
), add a space between 1
and 2
– Daniel F
Nov 20 at 16:53
1
1
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
This would only remove one instance of comma though, which is fair if that's all OP need.
– Idlehands
Nov 20 at 16:57
Also unbalanced quotes will introduced problems. See
'this is, not good", "type of ,question" to ask, on stackoverflow'
yields this is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
Also unbalanced quotes will introduced problems. See
'this is, not good", "type of ,question" to ask, on stackoverflow'
yields this is, not good" "type of ,question" to ask, on stackoverflow
– Daniel F
Nov 20 at 16:59
|
show 1 more comment
Another way that gives you some flexibility is you can do it by two steps:
Find all the matches that are contained in quotations,
In each match look for and replace the
','
.
Example:
# define a pattern that gets you everything inside a double quote
pat = re.compile(r'"[^"]+"')
# re.sub the quote pattern and replace the , in each of those matches.
string = pat.sub(lambda x: x.group(0).replace(',',''), string)
# 'this is, not good "type of question" to ask, on stackoverflow'
The flexibility of this is it allows you to replace as many ','
as you need, and you can perform other changes as well once you have located all the double quote patterns.
This should be higher up. My solution does not address multiple,
in a single quote, which is a big overlook on my part.
– Rocky Li
Nov 20 at 17:14
add a comment |
Another way that gives you some flexibility is you can do it by two steps:
Find all the matches that are contained in quotations,
In each match look for and replace the
','
.
Example:
# define a pattern that gets you everything inside a double quote
pat = re.compile(r'"[^"]+"')
# re.sub the quote pattern and replace the , in each of those matches.
string = pat.sub(lambda x: x.group(0).replace(',',''), string)
# 'this is, not good "type of question" to ask, on stackoverflow'
The flexibility of this is it allows you to replace as many ','
as you need, and you can perform other changes as well once you have located all the double quote patterns.
This should be higher up. My solution does not address multiple,
in a single quote, which is a big overlook on my part.
– Rocky Li
Nov 20 at 17:14
add a comment |
Another way that gives you some flexibility is you can do it by two steps:
Find all the matches that are contained in quotations,
In each match look for and replace the
','
.
Example:
# define a pattern that gets you everything inside a double quote
pat = re.compile(r'"[^"]+"')
# re.sub the quote pattern and replace the , in each of those matches.
string = pat.sub(lambda x: x.group(0).replace(',',''), string)
# 'this is, not good "type of question" to ask, on stackoverflow'
The flexibility of this is it allows you to replace as many ','
as you need, and you can perform other changes as well once you have located all the double quote patterns.
Another way that gives you some flexibility is you can do it by two steps:
Find all the matches that are contained in quotations,
In each match look for and replace the
','
.
Example:
# define a pattern that gets you everything inside a double quote
pat = re.compile(r'"[^"]+"')
# re.sub the quote pattern and replace the , in each of those matches.
string = pat.sub(lambda x: x.group(0).replace(',',''), string)
# 'this is, not good "type of question" to ask, on stackoverflow'
The flexibility of this is it allows you to replace as many ','
as you need, and you can perform other changes as well once you have located all the double quote patterns.
answered Nov 20 at 16:38
Idlehands
3,9871417
3,9871417
This should be higher up. My solution does not address multiple,
in a single quote, which is a big overlook on my part.
– Rocky Li
Nov 20 at 17:14
add a comment |
This should be higher up. My solution does not address multiple,
in a single quote, which is a big overlook on my part.
– Rocky Li
Nov 20 at 17:14
This should be higher up. My solution does not address multiple
,
in a single quote, which is a big overlook on my part.– Rocky Li
Nov 20 at 17:14
This should be higher up. My solution does not address multiple
,
in a single quote, which is a big overlook on my part.– Rocky Li
Nov 20 at 17:14
add a comment |
How about a combination of split()
and replace()
? :
s = 'this is, not good "type of ,question" to ask, on stackoverflow'
splitted = s.split('"')
print(s.replace(splitted[1], splitted[1].replace(',', '')))
# this is, not good "type of question" to ask, on stackoverflow
Note: This works in this case, but does not work in cases where you have the exact same string within double quotes outside the double quotes.
add a comment |
How about a combination of split()
and replace()
? :
s = 'this is, not good "type of ,question" to ask, on stackoverflow'
splitted = s.split('"')
print(s.replace(splitted[1], splitted[1].replace(',', '')))
# this is, not good "type of question" to ask, on stackoverflow
Note: This works in this case, but does not work in cases where you have the exact same string within double quotes outside the double quotes.
add a comment |
How about a combination of split()
and replace()
? :
s = 'this is, not good "type of ,question" to ask, on stackoverflow'
splitted = s.split('"')
print(s.replace(splitted[1], splitted[1].replace(',', '')))
# this is, not good "type of question" to ask, on stackoverflow
Note: This works in this case, but does not work in cases where you have the exact same string within double quotes outside the double quotes.
How about a combination of split()
and replace()
? :
s = 'this is, not good "type of ,question" to ask, on stackoverflow'
splitted = s.split('"')
print(s.replace(splitted[1], splitted[1].replace(',', '')))
# this is, not good "type of question" to ask, on stackoverflow
Note: This works in this case, but does not work in cases where you have the exact same string within double quotes outside the double quotes.
edited Nov 20 at 16:45
answered Nov 20 at 16:32
Austin
9,4423828
9,4423828
add a comment |
add a comment |
How about this:
b=""" "hello, howdy". sample text, text then comes "Another, double, quotes" """
for str_match in re.findall(r"".*?"",b):
b = re.sub(str_match,re.sub(r","," ",str_match),b)
print(b)
output: "hello howdy". sample text, text then comes "Another double quotes" '
add a comment |
How about this:
b=""" "hello, howdy". sample text, text then comes "Another, double, quotes" """
for str_match in re.findall(r"".*?"",b):
b = re.sub(str_match,re.sub(r","," ",str_match),b)
print(b)
output: "hello howdy". sample text, text then comes "Another double quotes" '
add a comment |
How about this:
b=""" "hello, howdy". sample text, text then comes "Another, double, quotes" """
for str_match in re.findall(r"".*?"",b):
b = re.sub(str_match,re.sub(r","," ",str_match),b)
print(b)
output: "hello howdy". sample text, text then comes "Another double quotes" '
How about this:
b=""" "hello, howdy". sample text, text then comes "Another, double, quotes" """
for str_match in re.findall(r"".*?"",b):
b = re.sub(str_match,re.sub(r","," ",str_match),b)
print(b)
output: "hello howdy". sample text, text then comes "Another double quotes" '
answered Nov 20 at 17:39
Akhilesha
113
113
add a comment |
add a comment |
I'm not completely sure if this will match all your requirements, but on the template you offer the following would return what you are looking for.
result = re.sub('("(?:[^"])*),((?:[^"])*")', r"1 2")
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
add a comment |
I'm not completely sure if this will match all your requirements, but on the template you offer the following would return what you are looking for.
result = re.sub('("(?:[^"])*),((?:[^"])*")', r"1 2")
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
add a comment |
I'm not completely sure if this will match all your requirements, but on the template you offer the following would return what you are looking for.
result = re.sub('("(?:[^"])*),((?:[^"])*")', r"1 2")
I'm not completely sure if this will match all your requirements, but on the template you offer the following would return what you are looking for.
result = re.sub('("(?:[^"])*),((?:[^"])*")', r"1 2")
edited Nov 20 at 16:52
answered Nov 20 at 16:44
Daniel F
6,24944864
6,24944864
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
add a comment |
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
Rocky Li's answer is cleaner, tough.
– Daniel F
Nov 20 at 16:51
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53397243%2fregex-find-substring-and-replace-characters-and-update-whole-string%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
It sounds like you already tried using
re.findall
,re.search
, andre.sub
, yes? Please share the code for each of those attempts.– Kevin
Nov 20 at 16:27
output: this is, not good "type of question" to ask, on stackoverflow
– Devanshu Khokhani
Nov 20 at 16:27
Is it
'string= this is, not good "type of ,question" to ask, on stackoverflow'
orstring = 'this is, not good "type of ,question" to ask, on stackoverflow'
?– Daniel F
Nov 20 at 16:29
What should happen if there are more than two quote marks in the string? What if there are an odd number of quote marks? What if there are two 'real' quote marks, and one escaped quote mark inside that quote?
– Kevin
Nov 20 at 16:29
1
If the only data the code needs to work on is the one example you gave, then you only have to do
result = 'this is, not good "type of question" to ask, on stackoverflow'
. If you're thinking "very funny, I actually need it to work on a variety of inputs", then that's exactly why I'm asking these clarifying questions :-)– Kevin
Nov 20 at 16:33