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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:52:19+00:00 2026-05-24T13:52:19+00:00

I have to parse a text where with is a key word if it

  • 0

I have to parse a text where with is a key word if it is not surrounded by square brackets. I have to match the keyword with. Also, there must be word boundaries on both side of with.

Here are some examples where with is NOT a keyword:

  • [with]
  • [ with ]
  • [sometext with sometext]
  • [sometext with]
  • [with sometext]

Here are some examples where with IS keyword

  • with
  • ] with
  • hello with
  • hello with world
  • hello [ world] with hello
  • hello [ world] with hello [world]

Anyone to help?
Thanks in advance.

  • 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-24T13:52:19+00:00Added an answer on May 24, 2026 at 1:52 pm

    You can look for the word with and see that the closest bracket to its left side is not an opening bracket, and that the closest bracket to its right side is not a closing bracket:

    Regex regexObj = new Regex(
        @"(?<!     # Assert that we can't match this before the current position:
         \[        #  An opening bracket
         [^[\]]*   #  followed by any other characters except brackets.
        )          # End of lookbehind.
        \bwith\b   # Match ""with"".
        (?!        # Assert that we can't match this after the current position:
         [^[\]]*   #  Any text except brackets
         \]        #  followed by a closing bracket.
        )          # End of lookahead.", 
        RegexOptions.IgnorePatternWhitespace);
    Match matchResults = regexObj.Match(subjectString);
    while (matchResults.Success) {
        // matched text: matchResults.Value
        // match start: matchResults.Index
        // match length: matchResults.Length
        matchResults = matchResults.NextMatch();
    }
    

    The lookaround expressions don’t stop at line breaks; if you want each line to be evaluated separately, use [^[\]\r\n]* instead of [^[\]]*.

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

Sidebar

Related Questions

I have this: curl -H \api_key:{key}\ http://api.wordnik.com/api/word.xml/dog/definitions How do I parse this (within the
I have to parse a tab-delimited text file with Ruby to extract some data
I have a text template with placehoders that I parse in order to replace
Suppose I have a text that I can easily parse. It consists of text
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
I have an XML file which I'd like to parse into a non-XML (text)
I want to create a program that will parse text for key words and
I have a string which contains, lets say word key 5 times. Each time
I have defined a pyparsing rule to parse this text into a syntax-tree... TEXT
I have the following JSON text to parse in Java: { items: [ {

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.