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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:38:24+00:00 2026-05-26T09:38:24+00:00

I must be doing my regex wrong. In the console I do db.triples.find({sub_uri: /.*pdf.*/

  • 0

I must be doing my regex wrong.

In the console I do

db.triples.find({sub_uri: /.*pdf.*/ }); and get the desired result.

My Java class looks like this, (I have set input=”pdf”):

    public static List<Triple> search(String input){

        DB db=null;
        try {
            db = Dao.getDB();
        }
        catch (UnknownHostException e1) {   e1.printStackTrace(); }
        catch (MongoException e1) {         e1.printStackTrace(); }

        String pattern = "/.*"+input+".*/";
System.out.println(input);      

                List<Triple> triples = new ArrayList<Triple>();
                DBCollection triplesColl = null;

                try {
                    triplesColl = db.getCollection("triples");      } catch (MongoException e) { e.printStackTrace();}

                {                   
                    Pattern match = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
                    BasicDBObject query = new BasicDBObject("sub_uri", match);

                    // finds all people with "name" matching /joh?n/i
                    DBCursor cursor = triplesColl.find(query);

                    if(cursor.hasNext()){
                    DBObject tripleAsBSON = cursor.next();
                        Triple t = new Triple();
                        t.setSubject(new Resource((String)tripleAsBSON.get("sub_uri")));

System.out.println(t.getSubject().getUri());                

                        triples.add(t);
                    }   
            }
        return triples;
    }

From the console I get 12 results as I should, from the Java code I get no results.

  • 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-26T09:38:25+00:00Added an answer on May 26, 2026 at 9:38 am

    Java doesn’t need/understand regex delimiters (/ around the regex). You need to remove them:

    String pattern = ".*"+input+".*";
    

    I’m also not sure if that regex is really what you want. At least you should anchor it:

    String pattern = "^.*"+input+".*$";
    

    and compile it using the Pattern.MULTILINE option. This avoids a severe performance penalty if a line doesn’t contain your sub-regex input. You are aware that input is a regex, not a verbatim string, right?

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

Sidebar

Related Questions

I find this very strange, must be something I'm doing wrong, but still... I'm
I must be doing something really wrong, but I can't find anything on this
I must be doing something wrong. I can't seem to find the answer to
I must be doing something wrong. I can't seem to execute my CustomValidator's ServerValidate
I must be doing something wrong here (because really, what are the chances of
I'm sure I must be doing something wrong. But can't for the life of
I have found out that I am doing WPF wrong and frustratingly must overhaul
I must be doing something totally stupid here, but I can't get the PLCrashReporter
Ok, I know I must be doing something wrong, but darned if I can
I must be doing something wrong public interface IActor { //actor stuff } public

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.