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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:35:15+00:00 2026-06-06T00:35:15+00:00

I am trying to write a simple Java function that will take a list

  • 0

I am trying to write a simple Java function that will take a list of Language Inputs and see if what I obtained from a database query matches. All of the strings in my database have been normalized to make searches easier. Here is an example.

Research Lab A wants participants that have any of the following language inputs (they are separated by the pipe character | ):

{English | English, Spanish | Spanish} 

In other words, this lab can take participants that are either monolingual English, monolingual Spanish, or bilingual English and Spanish. This is very straightforward – if they database result returns "English" or "English, Spanish" or "Spanish", my function will find a match.

HOWEVER, my database also marks if a participant only has minimal language input for some language (using the ~ character).

"English, ~Spanish" = participant hears English and a little Spanish
"English, ~Spanish, Russian" = participant hears English, Russian, and a little Spanish

This is where I am having trouble. I want to match something like "English, ~Spanish" with both "English" and "English, Spanish".

I was thinking of just remove/hiding the languages with a marked ~, but if there is a research lab that wants only {English, Spanish}, then "English, ~Spanish" will not match, even though it should.

I also cannot think of how I could use regular expressions to do this task. Any help will be greatly appreciated!

  • 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-06T00:35:16+00:00Added an answer on June 6, 2026 at 12:35 am

    Try this

    \b(English[, ~]+Spanish|Spanish|English)\b
    

    Code

    try {
        if (subjectString.matches("(?im)\\b(English[, ~]+Spanish|Spanish|English)\\b")) {
            // String matched entirely
        } else {
            // Match attempt failed
        } 
    } catch (PatternSyntaxException ex) {
        // Syntax error in the regular expression
    }
    

    Explanation

    "\\b" +               // Assert position at a word boundary
    "(" +                // Match the regular expression below and capture its match into backreference number 1
                            // Match either the regular expression below (attempting the next alternative only if this one fails)
          "English" +          // Match the characters “English” literally
          "[, ~]" +            // Match a single character present in the list “, ~”
             "+" +                // Between one and unlimited times, as many times as possible, giving back as needed (greedy)
          "Spanish" +          // Match the characters “Spanish” literally
       "|" +                // Or match regular expression number 2 below (attempting the next alternative only if this one fails)
          "Spanish" +          // Match the characters “Spanish” literally
       "|" +                // Or match regular expression number 3 below (the entire group fails if this one fails to match)
          "English" +          // Match the characters “English” literally
    ")" +
    "\\b"                 // Assert position at a word boundary
    

    UPDATE

    A more generalized form would be something like this:

    (?-i)\b([A-Z][a-z]+[, ~]+[a-z]+|[A-Z][a-z]+)\b
    

    BTW, doing so you might be messed up, as this pattern would going to match a all Capitalized word. There might be a better option to do so by using this syntax while generating your RegEx pattern.

    (A[, ~]+B|A|B)
    

    Where A, B would be name of languages. I think this would be a better approach.

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

Sidebar

Related Questions

I'm trying to write a simple recursive function that look over list and return
I'm trying to write a simple procedure that will add to a List every
I trying to write a simple function to call unmanaged code from managed code.
I'm trying to write a simple Vim function that takes the name of a
I'm new to java and am trying to write a simple program that basicly
I'm trying to write a simple game in Java that uses Processing to render
I'm trying to write a simple java applet program, but it seems that I'm
I'm trying to write a simple java program in Eclipse that prints these four
I just switched from C++ to Java. I'm trying to write a program that
I am trying to write a simple tool using Shoes. This will indent code

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.