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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:08:27+00:00 2026-06-02T04:08:27+00:00

OK, guys. Here’s a Java interview-type question that seems to have stumped some very

  • 0

OK, guys. Here’s a Java interview-type question that seems to have stumped some very smart people around here. They actually need this for production code, so it’s more than just an interview puzzler.

They need a regular expression, in Java, that returns true if a string literal is anything other than the 3-letter word NIL. The test needs to be case insensitive, and the RegEx itself must do all the work.

So, the RegEx should reject NIL, nil, NiL, nIL, and so on.

It should, however, accept: nile, anil, will, zappa-nil-a, and the empty string.

How many Java developers does it take to write a trivial RegEx? Apparently a lot!

  • 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-06-02T04:08:28+00:00Added an answer on June 2, 2026 at 4:08 am

    You can do this using a negative lookahead.

    With case-insensitive option enabled:

    ^(?!nil$).*
    

    You could leave off the .* at the end if you don’t need to actually return the string in the match. Here is a version without the case-insensitive option:

    ^(?![nN][iI][lL]$).*
    

    Explanation:

    ^       # start of string anchor
    (?!     # start negative lookahead (fail if...)
       nil    # literal characters 'nil'
       $      # end of string
    )       # end lookahead
    .*      # consume string (not necessary, but it acts more like a typical regex)
    

    If you want the regex to match nil\n, then use \z instead of $ in the lookahead: ^(?!nil\z).*

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

Sidebar

Related Questions

I have some guys here who have code that needs to be compiled with
guys! I've noticed that here are a lot of people who are familiar with
With the help of some of the guys here I have some regex to
Hey guys here is my question. im using JCombobox. if a student have CB
Rather basic question here guys. Basically I have code like this: public SuperPanel() {
Good morning/afternoon/evening guys Here is the thing. I'm making a registering gsp that it
Hey guys I have a little issue here. I have a panel where I
Hey guys got a quick question here, how do i set up TweetStream after
HI Guys, Here I am having problem that How can I post an image
Sorrry guys, I'm stuck here. I have a few grids, I also have CollectionViewSource

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.