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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:28:58+00:00 2026-06-17T15:28:58+00:00

[the JSoup discussion page suggested I ask my question here.] So, I am no

  • 0

[the JSoup discussion page suggested I ask my question here.]

So, I am no regex expert, but I’m wondering about the results I get from the jsoup
getElementsByAttributeValueMatching() method.

If I have an html page that has (among others) the following links:

<a href="/tweb/tiles/twr/EIDS_AT_20130108T134335/01/">Parent Directory</a>
<a href="1357681618315/">1357681618315/</a>
<a href="1357681649996/">1357681649996/</a>

And I query with:

Elements dirs = baseDir.getElementsByAttributeValueMatching("href", Pattern.compile("[0-9]+/"));

hoping to get just the 2 links that have only numbers (and a slash at the end.)

However, I get all 3 links back.

I wrote a quick test program to check java’s Pattern Matcher response to that regex with the 3 href strings, and it returns only the two with only numbers as I would expect:

String a = "/tweb/tiles/twr/EIDS_AT_20130108T134335/01/";
String b = "1357681618315/";
String c = "1357681649996/";

Pattern p = Pattern.compile("[0-9]+/");

System.out.println("a:"+ p.matcher(a).matches());
System.out.println("b:"+ p.matcher(b).matches());
System.out.println("c:"+ p.matcher(c).matches());

returns:
a:false
b:true
c:true

So, my question is, what am I missing?

thanks,
Linus

  • 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-17T15:29:00+00:00Added an answer on June 17, 2026 at 3:29 pm

    Jsoup uses Matcher#find(), not Matcher#matches(). So, you need to supply ^ and $ yourself.

    Elements dirs = baseDir.getElementsByAttributeValueMatching(
        "href", Pattern.compile("^[0-9]+/$"));
    

    Here are javadoc extracts of relevance explaining the difference (emphasis mine):

    find

    …

    Returns:

    true if, and only if, a subsequence of the input sequence matches this matcher’s pattern

    matches

    …

    Returns:

    true if, and only if, the entire region sequence matches this matcher’s pattern

    As to why Jsoup uses find() instead of matches(), that’s a question you’ve to ask to its creator.

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

Sidebar

Related Questions

I have used Jsoup to fetch a page from a URL. I can extract
Hi I have a problem with Jsoup. I scrape a page and get a
I use a Jsoup to get the Elements from a web: Elements addresses =
I'm trying to delete html tags from a string using JSoup, but at run
Is there anything like Jsoup but instead of parsing HTML, I need to parse
I was using JSoup in order to post data and call javascript functions, but
Very basic, But I don't know, How to add JSoup.jar to my android workspace?
Does Jsoup updates data from a website everytime one use the app.?? i.e if
I'm using JSoup in an attempt to built valid XML from a couple of
I am using Jsoup to extract data by zip codes from a Web site.The

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.