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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:53:26+00:00 2026-05-23T09:53:26+00:00

I have a logfile, where we parse each line using regex in Python. Part

  • 0

I have a logfile, where we parse each line using regex in Python.

Part of each line contains a phrase, which is one or more words.

For example, in the below, the phrase is “SOME PHRASE”.

12-09-95 10:37:46,082 [3] INFO Foobar <> - 1995-Dec-09 10:37:47.189025 --- [5571467078570868736::TYPE    ::SOME PHRASE ::1995-Dec-09 10:37:47.165672::1995-Dec-09 10:37:47.188790::00:00:00.023117]

In other lines, it may only be a single word, for example “PHRASE”.

12-09-95 10:37:46,082 [3] INFO Foobar <> - 1995-Dec-09 10:37:47.189025 --- [5571467078570868736::TYPE    ::SOME PHRASE    ::1995-Dec-09 10:37:47.165672::1995-Dec-09 10:37:47.188790::00:00:00.023117]

We need to extract all the words of the phrase, including any spaces in between words, but minus any whitespace either to the left or right of it.

The phrase itself is easy – the relevant part of our regex:

::(?P<phrase>[\w\s]+)::

However, I’m not sure how to discard the whitespace on the right using regex – the logfile usually have a bunch of extraneous spaces after the phrase we want.

I know I could just use str.rstrip() to remove it afterwards, but I’d rather use the regex expression itself to simply not pick it up – is there a way of doing this?

Cheers,
Victor

  • 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-23T09:53:27+00:00Added an answer on May 23, 2026 at 9:53 am

    You could not match trailing whitespace like so..

    ::(?P<phrase>[\w\s]+?)\s*::
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector which contains a list of files to open and parse,
i have a log file which contains hundreds/thousands of seperate XML messages and need
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a program in C# WPF which analyzes certain log files. Each log
I have a small problem. I have a tool which should parse a log
I have a logfile which logs the insert/delete/updates from all kinds of tables. I
I have a login.jsp page which contains a login form. Once logged in the
I want to parse a log file (log.txt) which contains rows similar to these:
I am trying to parse a logfile, using human readable dates without a year
I have managed to get my first python script to work which downloads a

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.