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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:37+00:00 2026-05-28T04:36:37+00:00

I have a pattern: \nvariable WORD This pattern shows up a lot of times

  • 0

I have a pattern:
“\nvariable WORD”

This pattern shows up a lot of times in the string and I want a list of indexes that this pattern shows up at. “WORD” is fixed, and doesn’t change from instance to instance, but “variable” varies in content and length.

In python, I know this matches all WORD and returns their indices in a list:

contents="some long string"
print [m.start() for m in re.finditer('WORD',contents)]

So in short, how do I find indices of all “variable” after \n but before “WORD”?

  • 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-28T04:36:37+00:00Added an answer on May 28, 2026 at 4:36 am

    If the only tool you know is a hammer, every problem looks like a nail.

    Regular expressions are powerful hammers, but sometimes not the best tool for the task in hand. In fact, regular expressions are abused a lot, I feel shivers down the spine every time someone asks me to check complex regular expressions from other programmer (often I’m unable understand mine after a few weeks).

    On the other side, EBNF (Extended Backus–Naur Form) notation is a lot easier to understand and maintain.

    from simpleparse.parser import Parser
    
    grammar = r"""
    <space>      := [ \t]
    <newline>    := '\n'
    <identifier> := [A-Za-z_],[A-Za-z0-9z_]*
    match        := newline,identifier,space+,'WORD'
    <junk>       := newline*,identifier,space+,-'WORD',(identifier/space)*
    data         := (match/junk)*
    """
    
    parser = Parser(grammar, 'data')
    
    data = 'some junk\nvariable1 WORD\nvariable2 some ' +\
           'junk\nvariable3 WORD\nvariable4 some other ' +\
           'junk\nvariable5 WORD'
    
    (start, matches, stop) = parser.parse(data)
    
    print [ start for name, start, stop, other in matches ]
    

    This will print:

    [9, 44, 85]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to match the word/pattern that is contained in the variable, but only
I have a string like this: N:string of unknown length\r\n I want string of
I have a pattern like this that matches multiple sets of values: (((\w+) (\d+))+)
I have a pattern with a small list of words that are illegal to
I have a loan pattern that applies a function n times where 'i' is
We have method that looks like this : public String getCommandString(Object...args) { return this.code
Ok I have some code that boils down to a pattern like this class
I have a pattern to match with the string: string pattern = @asc I
Ok so if I have this pattern: ab&bc&cd&de&ef And I need to replace all
I have the following string: [assembly: AssemblyVersion(1.0.0.0)] The issue now is that I have

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.