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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:07:54+00:00 2026-06-09T14:07:54+00:00

I am compiling a regex patter to match specific commands in a debug console,

  • 0

I am compiling a regex patter to match specific commands in a debug console, one of them is:

Pattern.compile("^\\s*\\\\connect\\s+((\\d{1,3}\\.){3}\\d{1,3})(?:\\s+(\\d+))?\\s*$");

so it is possible to enter

\connect 127.0.0.1 2345

or leave the port

\connect 127.0.0.1

spaces are ignored as long as I use at last one space to separate the fields.

It works perfectly, however, while the ip goes to group 1 (which is ok), the port goes to group 3 (as written, I know).

So I wanted to use an non-capturing group for the first three parts of the ip address:

Pattern.compile("^\\s*\\\\connect\\s+((?:\\d{1,3}\\.){3}\\d{1,3})(?:\\s+(\\d+))?\\s*$");

So I thought I would get the ip in group 1 and the port in group 2.
But now the Matcher.matches() returns false for the same input… Where is the problem?

  • 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-09T14:07:56+00:00Added an answer on June 9, 2026 at 2:07 pm

    Wild guess: The problem is somewhere else.
    I did a quick test:

            String test = "\\connect 127.0.0.1 2345";
        Pattern p1 = Pattern.compile("^\\s*\\\\connect\\s+((\\d{1,3}\\.){3}\\d{1,3})(?:\\s+(\\d+))?\\s*$");
        Pattern p2 = Pattern.compile("^\\s*\\\\connect\\s+((?:\\d{1,3}\\.){3}\\d{1,3})(?:\\s+(\\d+))?\\s*$");
    
        System.out.println(p1.matcher(test).matches());
        System.out.println(p2.matcher(test).matches());
    

    Output:
    true
    true

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

Sidebar

Related Questions

am new to regex, so am having a hard time compiling my own pattern.
It is possible to write a Regex which needs in some cases exponential running
I have to update this code to do a substring or regex match but
I'm trying to match on a line ending with something like: blocking=12345us The pattern
I'm using Sybase 12.5.3, and want/need to do regex pattern matching. The Sybase help
I have a problem compiling Haskell programs, that import the Text.Regex.Posix module. I have
I'm having trouble compiling the following code: #include <iostream> #include <string> #include <boost/regex.hpp> using
Compiling a kernel module on 32-Bit Linux kernel results in __udivdi3 [mymodule.ko] undefined! __umoddi3
Compiling this code with g++ 4.7.0 ( -Wall -Wextra -Werror -Wconversion -std=c++11 ): #include
In compiling qt I found that there is a qws target called arm-linux-gcc. I

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.