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 7828823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:29:47+00:00 2026-06-02T10:29:47+00:00

I am learning regular expressions using python 2.7 Given a sentence(assume lowercase and ascii)

  • 0

I am learning regular expressions using python 2.7

Given a sentence(assume lowercase and ascii) such as:

input = 'i like: a, b, 007 and c!!'

How would I tokenize the input string into

['i', 'like', ':', 'a', ',', 'b', ',', '007', 'and', 'c', '!!']

I can write the automata and code the transition matrix in C++, but I would like to do this in python

I am unable to come up with a regex that will match these distinct classes of alphabets, digits and punctuations in one go.

I have seen a couple of stackoverflow posts here and here, but do not quite follow their approaches.

I have tried this for some time now and I would appreciate your help on this.

P.S: This is not a homework question

  • 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-02T10:29:50+00:00Added an answer on June 2, 2026 at 10:29 am
    >>> from string import punctuation
    >>> text = 'i like: a, b, 007 and c!!'
    >>> re.findall('\w+|[{0}]+'.format(punctuation),text)
    ['i', 'like', ':', 'a', ',', 'b', ',', '007', 'and', 'c', '!!']
    

    This also works but finds any non-whitespace character if it doesn’t find alphanumeric characters

    >>> re.findall('\w+|\S+',text)
    ['i', 'like', ':', 'a', ',', 'b', ',', '007', 'and', 'c', '!!']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still learning PHP regular expressions (and regular expressions in general), and would like
Today, I am learning regular expressions =D I understand some basics, like \d+ matches
Using re in Python, I would like to return all of the characters in
I am learning about regular expressions and more specifically word boundries. I have a
I'm trying my hand in learning Regular Expressions in Oracle ( rather, my first
I m just learning regular expression matching using javascript, and have a doubt regarding
When learning regular expressions, I once saw the following four examples. How can I
I've been learning regular expressions for the last few days and I've been stumbled
I'm new to this site, and new to Python. So I'm learning about Regular
I've set myself a somewhat ambitious first task in learning regular expressions (and one

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.