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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:49:23+00:00 2026-06-13T13:49:23+00:00

I need a RegEx for Javascript which will match the string smith in lines

  • 0

I need a RegEx for Javascript which will match the string “smith” in lines 1-4 but not in lines 5-8 below.
The numbered lines are fields in an Access database (the fields do not contain the numbers).
What I have so far is:

var xy = 'smith';
MyString = new RegExp('(^|\\W)' + xy + '(\\W|$)', 'i');

This matches the Smiths in lines 1-4, but also those in Lines 7 and 8.
How can I get the expression to also ignore the Smiths which are preceded or followed by a hyphen?

  1. Smith, Jones, Wilson
  2. Smith Jones Wilson
  3. Jones, Smith(Jr), Wilson
  4. Jones, Wilson, Smith
  5. Arrowsmith, Jones
  6. Wilson, Smithson
  7. Jones, Smith-Treadstone, Wilson
  8. Wilson, Blakely-Smith, Jones

After a week and dozens of attempts, I am asking the experts!

  • 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-13T13:49:24+00:00Added an answer on June 13, 2026 at 1:49 pm

    Write the negative character class (\W) yourself and include the hyphen:

    MyString = new RegExp('(^|[^a-z0-9_-])' + xy + '([^a-z0-9_-]|$)', 'i');
    

    While \W matches any non-word character (everything but letters, digits and underscores), [^a-z0-9_-] matches any character that is neither such a word character nor a hyphen.

    You could of course use \w within that character class:

    MyString = new RegExp('(^|[^\\w-])' + xy + '([^\\w-]|$)', 'i');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regex (JavaScript) which will extract shortforms from a string for example
I need to use JavaScript split but I'm useless at regex so what i
I am trying to match the following string in Javascript Regex PC123456 This is
I need to match all occurrences of // in a string in a Javascript
I need a regex that can match a string of numbers from 1 to
I need a regex for date format in python I want March 29 but
I need a Regex I think to see if a string is only a
I need a regex that will give me the following results from each example
i need a regex to replace a string. <span class=\Translation\ lang=\ThisLanguage\> with this one:
I need to validate a date string in a specific format in Javascript. The

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.