Question: I'm looking for a code in python using regex that can perform something like this

Input: `Regex should return "String 1" or "String 2" or "String3"` 

Output: `String 1,String2,String3`

I tried `r'"*"'`

Answer: 
Here's all you need to do:

```
def doit(text):      
  import re
  matches = re.findall(r'"(.+?)"',text)
  # matches is now ['String 1', 'String 2', 'String3']
  return ",".join(matches)

doit('Regex should return "String 1" or "String 2" or "String3" ')

```

result:

```
'String 1,String 2,String3'

```

As pointed out by [Li-aung Yip](https://stackoverflow.com/users/1191425/li-aung-yip):

> 
> To elaborate, `.+?` is the "non-greedy" version of `.+`. It makes the regular expression match the smallest number of characters it can instead of the most characters it can. The greedy version, `.+`, will give `String 1" or "String 2" or "String 3`; the non-greedy version `.+?` gives `String 1`, `String 2`, `String 3`.
> 
> 
> 

In addition, if you want to accept empty strings, change `.+` to `.*`. Star `*` means zero or more while plus `+` means at least one.
```py
import re
r=r"'(\\'|[^'])*(?!<\\)'|\"(\\\"|[^\"])*(?!<\\)\""

texts=[r'"aerrrt"',
r'"a\"e'+"'"+'rrt"',
r'"a""""arrtt"""""',
r'"aerrrt',
r'"a\"errt'+"'",
r"'aerrrt'",
r"'a\'e"+'"'+"rrt'",
r"'a''''arrtt'''''",
r"'aerrrt",
r"'a\'errt"+'"',
      "''",'""',""]

for text in texts:
     print (text,"-->",re.fullmatch(r,text))

```

results: 

```py
"aerrrt" --> <_sre.SRE_Match object; span=(0, 8), match='"aerrrt"'>
"a\"e'rrt" --> <_sre.SRE_Match object; span=(0, 10), match='"a\\"e\'rrt"'>
"a""""arrtt""""" --> None
"aerrrt --> None
"a\"errt' --> None
'aerrrt' --> <_sre.SRE_Match object; span=(0, 8), match="'aerrrt'">
'a\'e"rrt' --> <_sre.SRE_Match object; span=(0, 10), match='\'a\\\'e"rrt\''>
'a''''arrtt''''' --> None
'aerrrt --> None
'a\'errt" --> None
'' --> <_sre.SRE_Match object; span=(0, 2), match="''">
"" --> <_sre.SRE_Match object; span=(0, 2), match='""'>
 --> None

```