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

The Archive Base Latest Questions

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

How to construct a regex not to contain a set of strings within. For

  • 0

How to construct a regex not to contain a set of strings within.

For this example, I want to validate the Address Line 1 text box so that it wont contain any secondary address parts such ‘Apt’, ‘Bldg’,’Ste’,’Unit’ etc.

  • 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-21T18:21:35+00:00Added an answer on May 21, 2026 at 6:21 pm

    A regex can be used to verify that a string does not contain a set of words. Here is a tested Java code snippet with a commented regex which does precisely this:

    if (s.matches("(?sxi)" +
        "# Match string containing no 'bad' words.\n" +
        "^                # Anchor to start of string.\n" +
        "(?:              # Step through string one char at a time.\n" +
        "  (?!            # Negative lookahead to exclude words.\n" +
        "    \\b          # All bad words begin on a word boundary\n" +
        "    (?:          # List of 'bad' words NOT to be matched.\n" +
        "      Apt        # Cannot be 'Apt',\n" +
        "    | Bldg       # or 'Bldg',\n" +
        "    | Ste        # or 'Ste',\n" +
        "    | Unit       # or 'Unit'.\n" +
        "    )            # End list of words NOT to be matched.\n" +
        "    \\b          # All bad words end on a word boundary\n" +
        "  )              # Not at the beginning of bad word.\n" +
        "  .              # Ok. Safe to match this character.\n" +
        ")*               # Zero or more 'not-start-of-bad-word' chars.\n" +
        "$                # Anchor to end of string.")
        ) {
        // String has no bad words.
        System.out.print("OK: String has no bad words.\n");
    } else {
        // String has bad words.
        System.out.print("ERR: String has bad words.\n");
    } 
    

    This assumes that the words must be “whole” words and that the “bad” words should be recognized regardless of case. Note also, (as others have correctly stated), that this is not as efficient as simply checking for the presence of bad words and then taking the logical NOT.

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

Sidebar

Related Questions

I have a simple problem: I want to construct a regex that matches a
I want to construct a regex, that matches either ' or and then matches
given a simple delimiter separated text database, I want to construct a regexp rule,
I am trying to check a valid Regex expression, with this class: using System.Text.RegularExpressions;
I would expect this Java regex to match all text in between two parentheses:
This has been driving me crazy. I need to construct a single regex expression
I would like to construct regex (in JavaScript) that would return: for string test
Which construct is better suited for this situation, an if-else or a switch? -
I am trying to construct a customized map in raphaeljs , in this i
Given this plain JavaScript construct: var MyObject = function() { var privateArray = [

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.