Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:54:24+00:00 2026-05-31T05:54:24+00:00

I have a string : mystring = Foo: Bar (Titi) Foo-age: 50 Airplanes: 12:1

  • 0

I have a string :

mystring = "Foo: Bar (Titi) Foo-age: 50 Airplanes: 12:1 12:3 12:4 12:5 [...] Next Hop: LAX Origine ID: 49 Hop List 2 4 9 0 3 [...]"

Is there a way to split this string using a pattern, like:

pattern = {"Foo", "Foo-age", "Airplanes", "Next Hop", "Origine ID", "Hop List"}

and then

mylist = somefunction(mystring , pattern)
print mylist 
--> {"Foo":"Bar (Titi)","Foo-age" : 50, "Airplanes": ["12:1","12:3",...], ...}

Is that possible in python?

[EDIT]

Some sample data – a 5-col csv file w/ delimiter “,”

col-1,col-2,Path: 9876 (IGP) Local-Pref: 310000   MED: 0 Communities: 1234:6 1234:95 1234:101 1234:202 1234:500 1234:903 1234:3369 1234:8000 1234:8002 1234:16925 9876:19827 Next Hop: x.x.127.151   Originator ID: x.x.155.144 Cluster List: 0.0.29.99 0.0.29.97 0.0.26.245 0.0.2.179 ,col-4,col-5

col-1,col-2,Path: 9876 (IGP) Local-Pref: 310000   MED: 0 Communities: 1234:3 1234:95 1234:101 1234:202 1234:13705 9876:19941 Next Hop: x.x.127.61   Originator ID: x.x.137.37 Cluster List: 0.0.29.99 0.0.29.97 0.0.1.195 ,col-4,col-5

col-1,col-2,Path: 9876 (IGP) Local-Pref: 310000   MED: 0 Communities: 1234:2 1234:95 1234:101 Next Hop: x.x.127.149   Originator ID: x.x.137.29 Cluster List: 0.0.29.99 0.0.29.98 0.0.2.240 ,col-4,col-5

col-1,col-2,Path: 9876 (IGP) Local-Pref: 310000   MED: 0 Communities: 1234:6 1234:95 1234:101 1234:202 1234:500 1234:903 1234:3369 1234:8000 1234:8002 1234:16924 9876:19827 Next Hop: x.x.127.151   Originator ID: x.x.155.144 Cluster List: 0.0.29.99 0.0.29.97 0.0.26.245 0.0.2.179 ,col-4,col-5
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:54:25+00:00Added an answer on May 31, 2026 at 5:54 am

    I think this can be done in two steps. First, you look for something that looks like a field name (Foo-Bar:) and insert a “special” marker character (e.g. @) before each match. Second, you look for the pattern marker field-name : data and populate the data dictionary:

    text = """
    col-1,col-2,Path: 9876 (IGP) Local-Pref: 310000   MED: 0 Communities: 1234:6 1234:95 1234:101 1234:202 1234:500 1234:903 1234:3369 1234:8000 1234:8002 1234:16925 9876:19827 Next Hop: x.x.127.151   Originator ID: x.x.155.144 Cluster List: 0.0.29.99 0.0.29.97 0.0.26.245 0.0.2.179 ,col-4,col-5
    """
    
    import re
    
    text = re.sub(r'([A-Z][A-Za-z -]+:)', r'@\1', text)
    data = {}
    for m in re.finditer(r'@(.+?):([^,@]+)', text):
        data[m.group(1)] = m.group(2).strip()
    
    import pprint
    pprint.pprint(data)
    

    Result:

     {'Cluster List': '0.0.29.99 0.0.29.97 0.0.26.245 0.0.2.179',
      'Communities': '1234:6 1234:95 1234:101 1234:202 1234:500 1234:903 1234:3369 1234:8000 1234:8002 1234:16925 9876:19827',
      'Local-Pref': '310000',
      'MED': '0',
      'Next Hop': 'x.x.127.151',
      'Originator ID': 'x.x.155.144',
      'Path': '9876 (IGP)'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a string which contains a mail address. For example ( user@foo.bar.com
I have string of 9 letters. string myString = 123987898; I want to retrieve
Let's assume I have the string NSString* myString = @Hello,; How can I remove
I have the following code: public class AppDomainArgs : MarshalByRefObject { public string myString;
I have a string value. NSString *myString = @Latitude:-31.9504140#Longitude:115.8606040; How can I retrieve the
If I have a string such as the following: String myString = SET(someRandomName, \hi\,
I have a string like so: mystring = test1, 1, anotherstring, 5, yetanother, 400;
I need to regex string myString to only have: 0-9 A-Z or a-z any
I have program that asks to enter a string (mystring) and a char (ch).
Suppose I have the following expression String myString = getStringFromSomeExternalSource(); if (myString != null

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.