Regex matching certain character in string pattern
Question: I have a example of many of string pattern like this but I want to show some
example.

    
    
    from:   [name:  Illianney Amada
    id:     674176087]
    from:   [name:  Natalia Morel-Gibbs
    id:     100003799207624]
    from:   [name:  Jules Kaneyge Pand
    id:     100000110811550]
    

And, I would like to illustrate the parameter type like this: (Watch
**String** and **SequenceOfNumber**)

    
    
    from:   [name:  String
    id:     SequenceOfNumber]
    

but actually, it was represented from this

    
    
    from:\t[name:\tString\nid:\tSequenceofNumber]
    

So, I would like to replace the **"\n"** that is between **"String"** and
**"id:"** with **",\t"** or tab character. The result should be like this

    
    
    from:\t[name:\tString,\tid:\tSequenceofNumber]\n
    from:\t[name:\tString,\tid:\tSequenceofNumber]\n
    from:\t[name:\tString,\tid:\tSequenceofNumber]\n
    

Or in other way like this

    
    
    from:   [name:  String,    id:     SequenceOfNumber]
    from:   [name:  String,    id:     SequenceOfNumber]
    from:   [name:  String,    id:     SequenceOfNumber]
    

Note: I implement the regex replacing with Python module **re**


Answer: **Update:**

    
    
    import re
    fixed = re.sub(r"(\[name:.*?)\n", r"\1,\t", originalString, re.M)
    

Results in:

    
    
    from:   [name:  Illianney Amada,       id:     674176087]
    from:   [name:  Natalia Morel-Gibbs,   id:     100003799207624]
    from:   [name:  Jules Kaneyge Pand,    id:     100000110811550]
    

Working example: <http://regex101.com/r/wN7aT0>

* * *

**Old:**

If you've only got the one `\n` there, you could do:

    
    
    originalString = "from:\t[name:\tString\nid:\tSequenceofNumber]"
    fixedString = ",\t".join(originalString.split("\n"))
    

This will split the string on `\n` and join it back together with `,\t`,
resulting in:

    
    
    from:\t[name:\tString,\tid:\tSequenceofNumber]
    

**Caveat:** in your original example, you didn't actually set a string in the
variable. Are you perhaps opening this from a text file? If so, that changes
the answer dramatically, because you might be looping one line at a time.

