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

  • Home
  • SEARCH
  • 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 61525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:19:58+00:00 2026-05-10T18:19:58+00:00

I want to use regular expressions (Perl compatible) to be able to find a

  • 0

I want to use regular expressions (Perl compatible) to be able to find a pattern surrounded by two other patterns, but not include the strings matching the surrounding patterns in the match.

For example, I want to be able to find occurrences of strings like:

Foo Bar Baz

But only have the match include the middle part:

Bar

I know this is possible, but I can’t remember how to do it.

  • 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. 2026-05-10T18:19:59+00:00Added an answer on May 10, 2026 at 6:19 pm

    In the general case, you probably can’t. The simplest approach is to match everything and use backreferences to capture the portion of interest:

    Foo\s+(Bar)\s+Baz 

    This isn’t the same as not including the surrounding text in the match though. That probably doesn’t matter if all you want to do is extract ‘Bar’ but would matter if you’re matching against the same string multiple times and need to continue from where the previous match left off.

    Look-around will work in some cases. Tomalak’s suggestion:

    (?<=Foo\s)Bar(?=\sBaz) 

    only works for fixed width look-behind (at least in Perl). As of Perl 5.10, the \K assertion can be used to effectively provide variable width look-behind:

    Foo\s+\KBar(?=\s+Baz) 

    which should be capable of doing what you asked for in all cases, but would require that you’re implementing this in Perl 5.10.

    While it would be convenient, there’s no equivalent of \K for ending the matched text, so you have to use a look-ahead.

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

Sidebar

Related Questions

I am not a beginner to regular expressions, but their use in perl seems
I am not really good at regular expressions, but I want to use only
I'm using Python and I want to use regular expressions to check if something
I am trying to use regular expressions to find a UK postcode within a
Firstly, I do not have the option to use Regular Expressions. It pains me
Lots of ready-to-use character classes are available in Perl regular expressions, such as \d
TL;DR I want to use Xcodes finder with regular expressions to update outdated function
VS2008 allows you to use regular expressions in the find/replace dialogs. I've run into
I want to use regular expression same way as string.Format. I will explain I
I want to use this regular expression in Python: <(?:[^]*[']*|'[^']*'[']*|[^'>])+> (from RegEx match open

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.