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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:03:50+00:00 2026-06-03T09:03:50+00:00

I’m not used to them and having trouble with the java syntax matches. I

  • 0

I’m not used to them and having trouble with the java syntax “matches”.

I have two files one is 111.123.399.555.xml the other one is Conf.xml.

Now I only want to get the first file with regular expressions.

string.matches("[1-9[xml[.]]]");

doesnt work.

How to do this?

  • 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-03T09:03:51+00:00Added an answer on June 3, 2026 at 9:03 am

    The use of string.matches("[1-9[xml[.]]]"); will not work because [] will create a character class group, not a capturing group.

    What this means is that, to java, your expression is saying "match any of: [1-to-9 [or x, or m, or l [or *any*]]]" (*any* here is because you did not escape the ., and as it, it will create a match any character command)


    Important:

    “\” is recognized by java as a literal escape character, and for it to be sent to the matcher as an actual matcher’s escape character (also “\”, but in string form), it itself needs to be escaped, thus, when you mean to use “\” on the matcher, you must actually use “\\”.

    This is a bit confusing when you are not used to it, but to sum it up, to send an actual “\” to be matched to the matcher, you might have to use “\\\\”! The first “\\” will become “\” to the matcher, thus a scape character, and the second “\\”, escaped by the first, will become the actual “\” string!


    The correct pattern-string to match for a ###.###.###.###.xml pattern where the “#” are always numbers, is string.matches("(\\d{3}\\.){4}xml"), and how it works is as follows:

    • The \\d = will match a single digit character. It is the same as
      using [0-9], just simpler.
    • The {3} specifies matching for “exactly 3 times” for the previous
      \\d. Thus matching ###.
    • The \\. matches a single dot character.
    • The () enclosing the previous code says “this is a capturing group”
      to the matcher. It is used by the next {4}, thus creating a “match
      this whole ###. group exactly 4 times”, thus creating “match ###.###.###.###.“.
    • And finally, the xml before the pattern-string ends will match
      exactly “xml”, which, along the previous items, makes the exact match for that pattern: “###.###.###.###.xml“.

    For further learning, read Java’s Pattern docs.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of 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.