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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:32:49+00:00 2026-05-14T04:32:49+00:00

I need to improve on a regular expression I’m using. Currently, here it is:

  • 0

I need to improve on a regular expression I’m using. Currently, here it is:

^[a-zA-Z\s/-]+

I’m using it to pull out medication names from a variety of formulation strings, for example:

  • SULFAMETHOXAZOLE-TRIMETHOPRIM 200-40 MG/5ML PO SUSP
  • AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
  • AMOXICILLIN TRIHYDRATE 125 mg ORAL TABLET, CHEWABLE
  • AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
  • Amoxicillin 1000 MG / Clavulanate 62.5 MG Extended Release Tablet

The resulting matches on these examples are:

  • SULFAMETHOXAZOLE-TRIMETHOPRIM
  • AMOX TR/POTASSIUM CLAVULANATE
  • AMOXICILLIN TRIHYDRATE
  • AMOX TR/POTASSIUM CLAVULANATE
  • Amoxicillin

The first four are what I want, but on the fifth, I really need “Amoxicillin / Clavulanate”.

How would I pull out patterns like “Amoxicillin / Clavulanate” (in fifth row) while missing patterns like “MG/5 ML” (in the first row)?

Update

Thanks for the help, everyone. Here’s a longer list of examples with more nuances of the data:

  • Amoxicillin 1000 MG / Clavulanate 62.5 MG Extended Release Tablet
  • Amoxicillin 1000 MG / Clavulanate 62.5 MG Extended Release Tablet
  • Amoxicillin 10 MG/ML Oral Suspension
  • Amoxil 10 MG/ML Oral Suspension
  • AMOXICILLIN TRIHYDRATE 125 mg ORAL TABLET, CHEWABLE
  • AMOXAPINE
  • AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
  • AMOXICILLIN TRIHYDRATE 125 mg ORAL TABLET, CHEWABLE
  • AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
  • AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
  • CARBATROL 200 MG PO CP12
  • CARBATROL 200 MG PO CP12
  • CARBATROL
  • CARBAMAZEPINE 100 MG PO CHEW
  • CEFDINIR 250 MG/5ML PO SUSR
  • AMOXICILLIN 400 MG/5ML PO SUSR
  • SULFAMETHOXAZOLE-TRIMETHOPRIM 200-40 MG/5ML PO SUSP
  • DIAZEPAM 2 MG PO TABS
  • DIAZEPAM
  • PREDNISONE 20 MG PO TABS
  • AUGMENTIN 250-62.5 MG/5ML PO SUSR
  • ACETAMINOPHEN 325 MG/10.15ML PO SUSP

What I’ve done for now is this:

    private static string GetMedNameFromIncomingConceptString(string conceptAsString)
    {
        // look for match at beginning of string
        Match firstRegMatch = new Regex(@"^[a-zA-Z\s/-]+").Match(conceptAsString);
        if (firstRegMatch.Success)
        {
            // grab matching part of string as whole string
            string firstPart = conceptAsString.Substring(firstRegMatch.Index, firstRegMatch.Length);

            // look for additional match following a hash (like Amox 1000 / Clav 50)
            Match secondRegMatch = new Regex(@"/\s[a-zA-Z\s/-]+").Match(conceptAsString, firstRegMatch.Length);
            if (secondRegMatch.Success) 
                return firstPart + conceptAsString.Substring(secondRegMatch.Index, secondRegMatch.Length);
            else
                return firstPart;
        }
        else
        {
            return conceptAsString;
        }
    }

It’s pretty ugly, and I imagine it may fail when I run a lot more data through it, but it works for the larger set of cases I listed above.

  • 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-14T04:32:49+00:00Added an answer on May 14, 2026 at 4:32 am

    When a slash is part of the dosage, is it always followed immediately by a digit? If so, this regex should do for you:

    ([A-Z]\D+)\d[^/]*(?:/\d[^/]*)*

    It actively matches the dosage information as the others suggested, but captures only the medication name. Then you do a global replace for $1 to delete the dosage. Here’s how I tested it in Java:

    String[] data = { 
      "SULFAMETHOXAZOLE-TRIMETHOPRIM 200-40 MG/5ML PO SUSP",
      "AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE",
      "AMOXICILLIN TRIHYDRATE 125 mg ORAL TABLET, CHEWABLE",
      "AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE",
      "Amoxicillin 1000 MG / Clavulanate 62.5 MG Extended Release Tablet"
    };
    Pattern p = Pattern.compile("([A-Z]\\D+)\\d[^/]*(?:/\\d[^/]*)*");
    Matcher m = p.matcher("");
    for (String s : data)
    {
      System.out.println(m.reset(s).replaceAll("$1"));
    }
    

    output:

    SULFAMETHOXAZOLE-TRIMETHOPRIM
    AMOX TR/POTASSIUM CLAVULANATE
    AMOXICILLIN TRIHYDRATE
    AMOX TR/POTASSIUM CLAVULANATE
    Amoxicillin / Clavulanate

    EDIT: Okay, it looks like the slash in the dosage is always followed by ML, which may be preceded by a number, which may include a decimal point. Also, the dosage information may be missing entirely. This regex seems to yield the desired result for your expanded sample input:

    ([A-Z]\D+)(?:$|\d[^/]*(?:/[\d.]*ML[^/]*)*)

    It should work in C#, too.

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

Sidebar

Ask A Question

Stats

  • Questions 430k
  • Answers 430k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure I understood your question correctly, but I… May 15, 2026 at 2:04 pm
  • Editorial Team
    Editorial Team added an answer Check out the connection strings web site which has tons… May 15, 2026 at 2:04 pm
  • Editorial Team
    Editorial Team added an answer As I understand it, the function "executes" each element in… May 15, 2026 at 2:03 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.