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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:06:21+00:00 2026-05-27T00:06:21+00:00

I am working on some socket programming stuff and attempting to match some strings.

  • 0

I am working on some socket programming stuff and attempting to match some strings. The format is as follows:

1.) Some text

where the one represents any number, and some text refers to anything (including letters, numbers, quotation marks, etc).

I tried using [0-9]*\\.\\).* but it doesn’t return a match. What am I doing wrong and how do I fix it?

Edit
As requested, here is my code:

/** Parses data returned by the server */
public void getSocketData(String data) {
    String[] lines = data.split("\\r?\\n");
    this.fileHosts = new String[lines.length];
    Pattern p = Pattern.compile("[0-9]*\\.\\).*");
    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];
        if (p.matcher(line).matches()) {
            //The format is: 1.) "b.jpg" from "192.168.1.101:40000"
            String[] info = line.split("\"");
            this.fileHosts[i] = info[3]; //this should now contain <addr:port>
            System.out.println("Adding " + fileHosts[i] + " to fileHosts");
        }
        else {
            System.out.println("No Match!");
        }
    }
}//getSocketData
  • 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-27T00:06:22+00:00Added an answer on May 27, 2026 at 12:06 am

    This works for me:

    public static void main(String args[]) {
        String s = "1.) Some text";
    
        System.out.println(s.replaceFirst("^[0-9]+\\.\\).*$","matched"));
    }
    

    Output:

    matched
    

    EDIT: Same result with the following:

    String s = "1.) \"b.jpg\" from \"192.168.1.101:40000\"";
    

    That is the example in the comment in your code

    EDIT2: I try also your code:

            String s = "1.) \"b.jpg\" from \"192.168.1.101:40000\"";
            Pattern p = Pattern.compile("^[0-9]+\\.\\).*$"); // works also if you use * instead of +
            if (p.matcher(s).matches()) {
                System.out.println("match");
            }
            else {
                System.out.println("No Match!");
            }
    

    The result is

    match
    

    Try using this regex: ^[0-9]+\\.\\).*$

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

Sidebar

Related Questions

I am working on some Python socket code that's using the socket.fromfd() function. However,
I'm currently working on a small project: there's a protocol for sending some strings
So, I'm working on some network programming in C, and it would seem that
Back again! I've been doing some async socket programming with select() on windows,and it's
For some reason, the zlib.deflate filter doesn't seem to be working with socket pairs
I am working on a feature that relies on socket communication. One test case
for some reason my server that uses socket.io is not working properly. The program
Working on some tweaks for a build script, I noticed that the output from
When working with some open source projects (in my case Joomla and Moodle), I've
Whilst working on some generally horrible Javascript code this morning, I came across 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.