Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with Regular Expressions

Posted on 2004-03-31
1
Medium Priority
?
275 Views
Last Modified: 2010-04-16
Hi,

I have a string

        s ='''740446505        "O'HANLON, Benjamin"'''

i need to use ONE RE pattern to convert it into
 
       (740446505, "O'HANLN", "Benjamin"),
including the brackets and the comma at the end.

I am using python 2.3 and have been stuydin the various tutotrials and the
howto websites for the past 3 days and haven't managed to find a solution.

Any help to get to the solution will be very very helpful.

Thanks,

Kunal
0
Comment
Question by:warturtle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 24

Accepted Solution

by:
fridom earned 80 total points
ID: 10746722
def transform (str):
     pat = re.compile("([0-9]+)  *([^,]*), *(.*)")
    m = pat.search(str)
    return "(" + m.group(1) + "," + m.group(2) + "," + m.group(3) + "),"

transform (s) yields
'(740446505,"O\'HANLON,Benjamin),'

Regards
Friedrich
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question