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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:49:51+00:00 2026-05-31T08:49:51+00:00

I need a java lib that will compare 2 different texts with some similarities

  • 0

I need a java lib that will compare 2 different texts with some similarities and tell me if they’re related or not.

For example, I would compare one of these

a) “COMP 150.00 MG X 20.00 UN”

b) “COMP 150.00 MG X 60.00 UN”

with this one

c) “150 mg comp.rec.x 20”

and the lib should tell me that the first one corresponds and the second doesn’t because a) and c) are both mentioning a medicine which is presented in “150mg capsules and the package brings 20 units” and b) refers to a 60 unit pack..

Another thought I had was about regular expressions, but I’m not quite into them so that’s why I’m asking for your help.

Thanks in advance.

  • 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-31T08:49:53+00:00Added an answer on May 31, 2026 at 8:49 am

    If the text variants are always structed in the same way, regular expressions could be one way to solve this. Basically you’d check each text against a set of expressions and see whether they match or not. Depending on how much the variants differ the expressions could be simple or might need to be more complex.

    For the case above, the first expression could look like this:

    COMP 150.00 MG X 20.00 UN -> (identifier) (capsule weight) X (num units)

    From this the following expression could be derived:
    ^COMP (\d+(?:\.\d+)?) MG X ([\d]+(?:\.\d+)?) UN$
    (this assumes that the number of spaces are always equal and that you always use MG and UN).

    The second expression:

    150 mg comp.rec.x 20 -> (capsule weight) comp.rec.x (num packages)

    The following expression could be derived:
    ^(\d+(?:\.\d+)?) mg comp\.rec\.x (\d+(?:\.\d+)?)$

    You’ll see that both expressions contain the following part twice: ([\d]+(?:\.\d+)?)

    Those parts capture numbers into a group and allow you to then parse that text into a Double, for example.
    Here’s a short breakdown of that sub-expression:

    • ( ... ) is a capturing group, i.e. you can access the part that matches that group directly
    • \d+ means one or more digits
    • \. is the literal dot
    • (?: ... ) is a non capturing group, i.e. you can apply quantifiers but can’t access the matched parts directly

    From the above parts you get the following:

    • (?:\.\d+)? means at most one dot followed by at least one digit. This would match .123 but not .1.2.3 or 1.
    • (\d+(?:\.\d+)?) means at least one digit, optionally followed by a dot which is followed by at least one more digit. This would match 1.23, 12.3 or 123 but not 1., .2 or 1.2.3.

    If you have those expressions, apply the correct one on the text (if you know it, otherwise test first) and extract both groups. Then compare the values of those groups.

    Note: don’t forget that in Java strings you have to escape backslashes, thus \d would be written as "\\d" etc.

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

Sidebar

Related Questions

I need to build a java based JSON data API that will be accessed
I need a java script function that converts the document object of the current
I am creating a desktop app that will create some reports. I want to
I'm using Ant to build some Java projects. In some, I've got a lib/
Due project requirements, I need to create a webapp that, when executing, will allow
Im looking for a Java lib that can read *.dif files saved from Excel
In a Java project, I am using a third-party library that loads some native
I need to modify the below makefile to create a dll (SampleNew.dll) that will
I will be hosting a java project on SVN which will need to be
I need a Java library to convert PDFs to TIFF images. The PDFs are

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.