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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:19:41+00:00 2026-06-15T12:19:41+00:00

Given the following sample strings: PP12111 LOREM IPSUM TM ENCORE LOREM PP12111 IPSUM TM

  • 0

Given the following sample strings:

PP12111 LOREM IPSUM TM ENCORE
LOREM PP12111 IPSUM TM ENCORE
LOREM IPSUM ENCORE TM PP12111
LOREM PP12111 PP12111 TM ENCORE

What would be a .NET RegEx to set title case and then convert any string containing numbers and letters to upper case (see note below):

PP12111 Lorem Ipsum TM Encore
Lorem PP12111 Ipsum TM Encore
Lorem Ipsum Encore TM PP12111
Lorem PP12111 PP12111 TM Encore

Alternativley, I can start with everything set to Title Case so only the strings containing numbers and letters need to be set to upper case:

Pp12111 Lorem Ipsum TM Encore
Lorem Pp12111 Ipsum TM Encore
Lorem Ipsum Encore TM Pp12111
Lorem Pp12111 Pp12111 TM Encore

Note: if any variant of TM exists (tm, Tm, tM), the it should be full upper case. Where the TM could be “lorem ipsum TM valor” or “lorem ipsum (TM) valor”.

Here is a pure string manipulation method that works; I would think that a RegEx solution may be a better fit?

private static void Main( string[] args )
{
    var phrases = new[]
        {
          "PP12111 LOREM IPSUM TM ENCORE", "LOREM PP12111 IPSUM TM ENCORE",
          "LOREM IPSUM ENCORE TM PP12111", "LOREM PP12111 PP12111 TM ENCORE",
        };

    Test(phrases);
}

private static void Test( IList<string> phrases )
{
    var ti = Thread.CurrentThread.CurrentCulture.TextInfo;

    for( int i = 0; i < phrases.Count; i++ )
    {
        string p = ti.ToTitleCase( phrases[i].ToLower() );
        string[] words = p.Split( ' ' );

        for( int j = 0; j < words.Length; j++ )
        {
            string word = words[j];
            if( word.ToCharArray().Any( Char.IsNumber ) )
            {
                word = word.ToUpper();
            }
            words[j] = word.Replace( " Tm ", " TM " ).Replace( "(Tm)", "(TM)" );
        }

        phrases[i] = string.Join( " ", words );

        Console.WriteLine( phrases[i] );
    }
}
  • 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-15T12:19:42+00:00Added an answer on June 15, 2026 at 12:19 pm

    You can use this regex like this:

    MatchEvaluator evaluator = m => ti.ToTitleCase(m.Value.ToLower());
    string result = Regex.Replace(input, @"\b(?!TM\b)[A-Z']+\b", evaluator,
                                  RegexOptions.IgnoreCase);
    

    \b                       Is a word boundary.
    pos(?!suffix) Matches position not preceeding suffix.
    \b(?!TM\b)       Word boundary not preceeding TM
    [A-Z]+               Words without digits.

    Together: Word boundary not preceeding “TM” followed by words with letters A through Z and word boundary.


    UPDATE #1

    Upper casing “tm”, “Tm”, “tM”:

    I don’t know if everything not capitalized can be upper case. In that case the easiest solution would be to upper case the input: input.ToUpper(). Otherwise execute a second regex replace:

    string result = Regex.Replace(result, @"\btm\b", "TM", RegexOptions.IgnoreCase);
    

    UPDATE #2

    If you want to upper case several words, you can just use another match evaluator:

    MatchEvaluator toUpperCase = m => m.Value.ToUpper();
    string result = Regex.Replace(result, @"\b(tm|xxx|yyy)\b", toUpperCase,
                                  RegexOptions.IgnoreCase);
    

    tm|xxx|yyy specifies the words to be upper cased (“tm”, “xxx” or “yyy”).

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

Sidebar

Related Questions

Given the following code sample: uint8_t i, in, ni; i = in = 2;
Given the following URIs sample: /index.site.rooms.98.html /index.site.rates.665678.html I need to capture the string which
Given the following MSDN sample code, why can't I define the Action delegate inline:
Given the following sample: public class Main { public static void main(String[] args) {
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Given the following sample code; class Program { static void Main(string[] args) { var
I would like to import the following csv as strings not as int64. Pandas
Given the following sample XML (here I am showing hard-coded, but normally I load
Given the following array: var things = ['sandwich', 17, 'fake@sample.com', 3, 'horse', 'octothorpe', 'anotheremail@sample.com',
In Powershell given the following string $string = this is a sample of 'my'

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.