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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:34:35+00:00 2026-05-22T18:34:35+00:00

Here is sample text(simplified from original): <start1> <name=4654> bla bla bla bla <tags=bla model=c>

  • 0

Here is sample text(simplified from original):

<start1>
<name="4654">
bla bla bla bla
<tags="bla" model="c">
bla bla bla bla
<start2>
<name="12346">
bla bla bla bla
<tags="bla" model="d">
bla bla bla bla
<start3>
<name="73535">
bla bla bla bla
<tags="bla" model="c">
<start4>
<name="546875">
bla bla bla bla
<tags="bla" model="c">
bla bla bla bla

Here is my regex(dot matches new line option is on)

name="([\d]+)".+?(?<!start)tags="([^"]+?)" model="c"

As you can see there are 4 blocks, but I need to match those with model=”c”. However .+? is capturing more than it needs. Puting negative lookbehind to suppress it did not work… Any idea how can I exclude block?

Update(to clarify what I want to achieve):

out of sample data I want to match following 3 blocks:

First match

<name="4654">
bla bla bla bla
<tags="bla" model="c">

Second match

<name="73535">
bla bla bla bla
<tags="bla" model="c">

Third match

<name="546875">
bla bla bla bla
<tags="bla" model="c">
  • 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-22T18:34:36+00:00Added an answer on May 22, 2026 at 6:34 pm

    Is it always in this format of (start, name, tags), (start, name, tags), and so on? If so, you can even do without the lookaround.

    /<name="(\d+)"[^<]+?<tags="([^"]+?)" model="c">/s
    

    That works because you know the next < you encounter will be for the immediately following tags label. Can we guarantee that’s the case, or do we need to be more general to allow for other labels in the mix?

    Also, do you need to capture the text after <tags> and before the next <start>? If so, you could add a little extra to the end for that.

    /<name="(\d+)"[^<]+?<tags="([^"]+?)" model="c">[^<]*(?!<start)/s
    

    Okay, according to your comments, that’s not the case. Scratch that, then.


    Update

    Okay, how ’bout this then?

    /<name="(\d+)"(?:(?!<start).)+<tags="([^"]+?)" model="c">/s
    

    This actually uses a lookahead, not a lookbehind. A simple lookahead/lookbehind will only assert that a string occurs before or after a block of text, not within. By checking at every character with ((?!str).)+, you effectively ensure that “str” is not contained throughout the text.

    It might look confusing that I’m using a lookahead to check for <start, whereas a lookbehind for start would look like (?<!start) instead of (?!<start).
    Think (?!(<start)) versus (?<!(start)).

    I added (?: ) just so it wouldn’t capture.

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

Sidebar

Related Questions

In QMessageBox how can I make the title text bold? Here is the sample
Simple question, I just want to select the text from the <Template> tag. Here's
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
Here is a sample from Kernighan & Ritchie's The C Programming Language: int getline(char
Here is a sample code to retrieve data from a database using the yield
Here is some sample text I'm using with sed (in bash, centos). I've broken
here is sample of the text file I am working with: <Opera> Tristan/NNP and/CC
Here is a sample of text that I’m working with: Word1 Word2 ... Word4
Here is a simple program to output to a text file: #include <iostream> #include
a simple question here Is there a way to change the text click here

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.