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

  • SEARCH
  • Home
  • 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 8861367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:28:39+00:00 2026-06-14T15:28:39+00:00

I am new to using regular expression in python. I am having trouble figuring

  • 0

I am new to using regular expression in python. I am having trouble figuring out how to do the following:

I have a bunch of text description as strings that looks like this:

FX0XST001ALF89  OLIGO: Bacillus_cand1=ATGCGGTTCAAAATGTTATC      
FILE:/home/AAFC-AAC/fungs/biodiversity/pipelines/454PipelineOutput/v7_newest_testrun_full/rs75/plate1/FX0XST001.MID13/FX0XST001.MID13.sff.trim.fasta    
Project: SAGES  SFF: FX0XST001  SFF.MID: FX0XST001.MID13    
Plate: 1.1     MID_all: MID13   MID: 13 Sample: BK104   
Collector: BK   Year: 2008  Week:   Year_Week:  
Location: Ottawa_ON     City: Ottawa    Province: ON    Crop:   
Treatment:    Substrate_all: Air    Substrate: Air  Target: Bacteria    
Forward Primer: Bac16S27F   Reverse Primer: Bac16S690R  Taq: T

I want to be able extract the categories inside this large string and store them into a database or something, for example:

Year: 2008
Sample: BK104
Collector: BK

etc...

How can I use regular expression in python to achieve this?

I am thinking of using search:

match = re.search(r'Sample:\w\w\w\w\w', theTextDescription)

The problem is the length of the text in each ‘field’ is different. I don’t really know how to take that into consideration

  • 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-06-14T15:28:40+00:00Added an answer on June 14, 2026 at 3:28 pm

    something like this, you can use \w+ to match characters to any number of length:

    In [37]: strs
    Out[37]: 'FX0XST001ALF89  OLIGO: Bacillus_cand1=ATGCGGTTCAAAATGTTATC      \nFILE:/home/AAFC-AAC/fungs/biodiversity/pipelines/454PipelineOutput/v7_newest_testrun_full/rs75/plate1/FX0XST001.MID13/FX0XST001.MID13.sff.trim.fasta    \nProject: SAGES  SFF: FX0XST001  SFF.MID: FX0XST001.MID13    \nPlate: 1.1     MID_all: MID13   MID: 13 Sample: BK104   \nCollector: BK   Year: 2008  Week:   Year_Week:  \nLocation: Ottawa_ON     City: Ottawa    Province: ON    Crop:   \nTreatment:    Substrate_all: Air    Substrate: Air  Target: Bacteria    \nForward Primer: Bac16S27F   Reverse Primer: Bac16S690R  Taq: T'
    
    In [38]: re.findall(r"\w+:\s\w+",strs)
    Out[38]: 
    ['OLIGO: Bacillus_cand1',
     'Project: SAGES',
     'SFF: FX0XST001',
     'MID: FX0XST001',
     'Plate: 1',
     'MID_all: MID13',
     'MID: 13',
     'Sample: BK104',
     'Collector: BK',
     'Year: 2008',
     'Location: Ottawa_ON',
     'City: Ottawa',
     'Province: ON',
     'Substrate_all: Air',
     'Substrate: Air',
     'Target: Bacteria',
     'Primer: Bac16S27F',
     'Primer: Bac16S690R',
     'Taq: T']
    

    or may be store it in a dictionary:

    In [39]: dict(x.split(":") for x in  re.findall(r"\w+:\s\w+",strs))
    Out[39]: 
    {'City': ' Ottawa',
     'Collector': ' BK',
     'Location': ' Ottawa_ON',
     'MID': ' 13',
     'MID_all': ' MID13',
     'OLIGO': ' Bacillus_cand1',
     'Plate': ' 1',
     'Primer': ' Bac16S690R',
     'Project': ' SAGES',
     'Province': ' ON',
     'SFF': ' FX0XST001',
     'Sample': ' BK104',
     'Substrate': ' Air',
     'Substrate_all': ' Air',
     'Taq': ' T',
     'Target': ' Bacteria',
     'Year': ' 2008'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using new style classes in Python 2.6 and am having trouble with __getattr__
I'm very new in regular expression and I'm trying to validate date using following
I have been using this regular expression to extract file names out of file
I am having issues figuring out how to split on multiple delimiters using regular
i am very new to regular expression and trying get \ character using python
Bear with me, as I'm quite new to using regular expressions. I have regexp
I am using Python and a regular expression to find an ORF (open reading
Using str.format() is the new standard for formatting strings in Python 2.6, and Python
I have this regular expression in c#: Regex oRegex_ = new Regex(<!-- #BeginEditable \Body\[^>]*>(.*)<!--
I am using regular expression first time, and I really amazed! well, new discovery

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.