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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:50:26+00:00 2026-06-03T19:50:26+00:00

i am having a python string of format mystr = hi.this(is?my*string+ here i need

  • 0

i am having a python string of format

mystr = "hi.this(is?my*string+"

here i need to get the position of ‘is’ that is surrounded by special characters or non-alphabetic characters (i.e. second ‘is’ in this example). however, using

mystr.find('is')

will return the position if ‘is’ that is associated with ‘this’ which is not desired. how can i find the position of a substring that is surrounded by non-alphabetic characters in a string? using python 2.7

  • 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-03T19:50:28+00:00Added an answer on June 3, 2026 at 7:50 pm

    Here the best option is to use a regular expression. Python has the re module for working with regular expressions.

    We use a simple search to find the position of the "is":

    >>> match = re.search(r"[^a-zA-Z](is)[^a-zA-Z]", mystr)
    

    This returns the first match as a match object. We then simply use MatchObject.start() to get the starting position:

    >>> match.start(1)
    8
    

    Edit: A good point made, we make "is" a group and match that group to ensure we get the correct position.

    As pointed out in the comments, this makes a few presumptions. One is that surrounded means that "is" cannot be at the beginning or end of the string, if that is the case, a different regular expression is needed, as this only matches surrounded strings.

    Another is that this counts numbers as the special characters – you stated non-alphabetic, which I take to mean numbers included. If you don’t want numbers to count, then using r"\b(is)\b" is the correct solution.

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

Sidebar

Related Questions

Having an UTF-8 string like this: mystring = işğüı is it possible to get
I'm having a problem with Python's subprocess.Popen method. Here's a test script which demonstrates
I am having some trouble getting Python IO redirected to a console that I've
Is there a string literal form in Objective-c that does not require escaping special
I read that I can use Python's Format Specification Mini-Language to have more control
I'm trying to substitute something in a string in python and am having some
I'm a programming newbie having difficulty with Python multiplication. I have code like this:
I am having the same problem as: python adds "E" to string All the
I'm having the following problem in python. I need to do some calculations in
The problem I am having at this point in time (being new to Python)

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.