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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:34:22+00:00 2026-05-23T07:34:22+00:00

We have a client application where the users want to search notes fields for

  • 0

We have a client application where the users want to search “notes” fields for specified text. The fields are either formatted with HTML or plaintext. One of the recent changes that we made was to only support “whole word” matches. Using \b, we made this happen. Pattern:

"\b(?:match)\b" <-- works

New day, new problem: one of the values that they want to find is a number followed by a percent sign. (%) However, the pattern doesn’t match. After some research, I was able to determine that, for a character at position n to be considered an end-of-word boundary, \b asserts that the character at position n – 1 must be a word character. However, % is not a word character, so the match fails.

"\b(?:7.0%)\b" <-- fails

I changed this to match \W, and it works, but this has the drawback that there must always be another character following the matched pattern.

"\b(?:7.0%)\W" <-- works, mostly

So what I want to know is, can I use the following as a pattern and have it match end-of-string matches?

"\b(?:7.0%)(\W|$)" <-- ??

I tested it and it appears to work, but is there anything that is going to bite me down the road?

Edit:

Here’s a quick test harness that demonstrates the different behaviors, including the answer from agent-j:

List<string> testInputs = new List<string>();

testInputs.Add("This string contains 7.0% embedded within it.");
testInputs.Add("In this string, 7.0%\nis at the end of a line.");
testInputs.Add("7.0% starts this string.");
testInputs.Add("This string ends with 7.0%");

List<string> testPatterns = new List<string>();
testPatterns.Add(@"\b(?:7.0%)\b");
testPatterns.Add(@"\b(?:7.0%)\W");
testPatterns.Add(@"\b(?:7.0%)(\W|$)");
testPatterns.Add(@"\b(?:7.0%)(?!\w)");

foreach (var patt in testPatterns)
{
    Console.WriteLine(string.Format("Testing pattern '{0}'", patt));

    foreach (var input in testInputs)
    {
        Console.WriteLine(string.Format("Input '{0}'; result: {1}", input, Regex.IsMatch(input, patt)));
    }

    Console.WriteLine();
}

Output:

Testing pattern '\b(?:7.0%)\b'
Input 'This string contains 7.0% embedded within it.'; result: False
Input 'In this string, 7.0%
is at the end of a line.'; result: False
Input '7.0% starts this string.'; result: False
Input 'This string ends with 7.0%'; result: False

Testing pattern '\b(?:7.0%)\W'
Input 'This string contains 7.0% embedded within it.'; result: True
Input 'In this string, 7.0%
is at the end of a line.'; result: True
Input '7.0% starts this string.'; result: True
Input 'This string ends with 7.0%'; result: False

Testing pattern '\b(?:7.0%)(\W|$)'
Input 'This string contains 7.0% embedded within it.'; result: True
Input 'In this string, 7.0%
is at the end of a line.'; result: True
Input '7.0% starts this string.'; result: True
Input 'This string ends with 7.0%'; result: True

Testing pattern '\b(?:7.0%)(?!\w)'
Input 'This string contains 7.0% embedded within it.'; result: True
Input 'In this string, 7.0%
is at the end of a line.'; result: True
Input '7.0% starts this string.'; result: True
Input 'This string ends with 7.0%'; result: True
  • 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-23T07:34:23+00:00Added an answer on May 23, 2026 at 7:34 am

    You are one the right track. Your expression \b(?:7.0%)(\W|$) will match the character following 7.0% when there is a character. Instead, consider using a negative lookahead (?!\w), so that extra character is not a part of your match.

    \b(?:7.0%)(?!\w)
    

    If the string ends with 7.0%, it will match, and if the string ends with 7.0%. it will match 7.0%. It will match whether or not your regex options say singleline or multiline.

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

Sidebar

Related Questions

i have a server - client application that runs on java 1.3; i want
I have a client/server application written in C#/.NET 3.5 that I want to do
I have client application that uses WCF service to insert some data to backend
I have a client-server application that uses .net remoting. The clients are in a
I have a client server application in which I need to transmit a user
I have a client of my web based application who heavily uses the data
I have C# Client application calling Windows webservice written in WCF calling Sql Procedure
We have a client application that needs to send messages to a server for
We have a client/server application with a rich client front end (in .Net) and
I have a client/server application that communicates with .Net remoting. I need my clients

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.