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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:53:04+00:00 2026-06-18T19:53:04+00:00

I am getting a different output in python 2 and 3 when I execute

  • 0

I am getting a different output in python 2 and 3 when I execute same code for regular expression.

Suppose this is the data that I want which is located somewhere in the webpage.

source = ['\x1e\x1e5.5.30-log\x1epcofiowa@localhost\x1epcofiowa_pci\x1e',
          '\x1e\x1e5.5.30-log\x1epcofiowa@localhost\x1epcofiowa_pci\x1e', 
          '\x1e\x1e5.5.30-log\x1epcofiowa@localhost\x1epcofiowa_pci\x1e', 
          '\x1e\x1e5.5.30-log\x1epcofiowa@localhost\x1epcofiowa_pci\x1e']

So, when I run the below code in python 2.6, it works perfect. I’m getting exact output like above.

match = re.findall("\x1e\x1e\S+",source)

But when I execute it in python 3.3 like:

match = re.findall("\x1e\x1e\S+", str(source))

I’m getting the output of the match variable like:

['\x1e\x1e5.5.30-log', '\x1e\x1e5.5.30-log', '\x1e\x1e5.5.30-log','\x1e\x1e5.5.30-log']

So, would you please tell me that why it’s not taking whole string in python 3? Why it’s skipping \x1epcofiowa@localhost\x1epcofiowa_pci\x1e each time? I want output like python 2.6.

So, I am clueless at this moment. I’m waiting for your reply. Thanks.

  • 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-18T19:53:05+00:00Added an answer on June 18, 2026 at 7:53 pm

    Seems like \S behave differently in Python 2 and Python 3.

    According to Python 3 re module docs: –

    \S – Matches any character which is not a Unicode whitespace
    character. This is the opposite of \s. If the ASCII flag is used this
    becomes the equivalent of [^ \t\n\r\f\v] (but the flag affects the
    entire regular expression, so in such cases using an explicit [^
    \t\n\r\f\v]
    may be a better choice).

    Now, since \x1e (equivalent to U+001E, that comes after your \x1e\x1e5.5.30-log is a unicode whitespace character – reference to activestate, so it is not matched by \S in Python 3.


    Whereas in Python 2: –

    \S – Matches any non-whitespace character; this is equivalent to the
    class [^ \t\n\r\f\v].

    So, it only considers the ASCII character set for matching non-whitespace, and hence it matches \x1e.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting an XML document output from Cognos which I want to use
This is my code and I am getting varied output. import threading import time
I am running these two commands, and I'm getting different output: $ ldd `which
Given the following code why am I getting different values for a and b
I've never had this issue before, so I'm somewhat lost. I'm getting two different
Can anyone explain why I would be getting a different ordering of the output
I'm building a Python ISO generation app, and I'm getting some wierd output from
I want to store the intermediate values of a variable in Python. This variable
I've got a socket from which I'm reading XML data. However, this socket will
I have following piece of code which posts some data into database: $post =

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.