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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:17:34+00:00 2026-05-30T19:17:34+00:00

I try to use Eclipse’s RegEx search function to search for the words ‘foo’

  • 0

I try to use Eclipse’s RegEx search function to search for the words ‘foo’ or ‘bar’, ignoring comments.

This is what I’ve got so far:

^(?!\s*(//|\*)).*(foo|bar)

The comment restrictions of my solutions are okay for me (anyway, if somebody has a better solution without dramatically extending the regex, I’d be glad to hear about it):

  • Single-line comments have to start at the beginning of the line, maybe indented (so I don’t care that return null; // foo won’t be ignored).
  • Multi-line comments start at the beginning of the line with a single asterisk, maybe indended (so /* foo won’t be ignored, while bar \n * foo will be ignored even though it’s not really a comment).

My problem is, that now the whole line up to (and including) ‘foo’ or ‘bar’ is highlighted in the search results. I only want ‘foo’ or ‘bar’ (or both, if both appear in the same line) to be highlighted.
I tried to include a positive look-ahead (in several variants) to achieve this:

^(?!\s*(//|\*))(?=.*)(foo|bar)

This results in no results. I don’t understand why. Thanks for any hint!

  • 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-30T19:17:36+00:00Added an answer on May 30, 2026 at 7:17 pm

    The problem is that lookaround assertions don’t actually match and consume any text. So in the regex

    ^(?!\s*(//|\*))(?=.*)(foo|bar)
    

    the texts foo or bar can only be matched at the start of the line because the regex engine hasn’t yet moved after matching all the lookaheads.

    That means if you don’t want the text leading up to foo/bar to be matched, you need a look*behind* assertion instead. However, only .NET and JGSoft regex engines support indefinite quantifiers like the asterisk inside a lookbehind assertion. Java/Eclipse do not support this.

    In .NET, you could search for

    (?<!^\s*(//|\*).*)(foo|bar)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use the following code: ArrayList<String> Map<String, String> Eclipse complains about both
I try to use this code for toggling text on the link: var showText=<span>Open</span>
I try to use this mapping : @Entity @Table(name=ecc.\RATE\) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=DISCRIMINATOR, discriminatorType= DiscriminatorType.STRING) public
I am getting the following error when I try to use the Eclipse IDE
Try to use tips for Eclipse performance I try to add option in eclipse.ini
When I try to use HaskellFP for Eclipse, I always get a popup that
I try to use Emacs+ plugin for Eclipse. There is four ways to split
I've installed and configured Pydev with Eclipse but when I try to use interactive
I'm working on a school project in eclipse, and when I try and use
i try to use an org.eclipse.jface.viewers.CheckboxTableViewer, as a component of a org.eclipse.jface.wizard.WizardPage. I created

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.