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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:36:37+00:00 2026-06-05T10:36:37+00:00

have a such issue with regexp in java. I code chat application and client

  • 0

have a such issue with regexp in java. I code chat application and client could sent to the server just “message” or “\command value”. I want to parse this string and check was a command i the line or not. If it login – value is required, but if it logout value.required should be false. I create such regexp

"^\\\\(?<comm>login|status|((?=logout)))\\s(?<content>\\w+)"

What should i write to logout condition? I want to have logout in comm group. I should write
something like if logout than do not read anything else which steps after.

  • 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-05T10:36:40+00:00Added an answer on June 5, 2026 at 10:36 am

    I would probably do the checking for whether a certain command should have a parameter or not in general purpose code (i.e. Java) rather than in the regular expression. That is to say, Regular Expressions are good for tokenizing, but not so much for parsing.

    However, if you’ve got a good reason to do it that way, then I would probably split the expression into two parts – one where the commands require a command, and one where they do not. For example:

    ^\\(?:(?<command>login)\s+(?<param>\w+)|(?<command>status|logout)(?<param>))$
    

    Note that the final (?<param>) is not strictly necessary for the regular expression to operate correctly, it is merely there so that any subsequent code can rely on two named groups in the result: command and param.

    Logically, this could be extended to three groups where the third group contains commands with an optional parameter.

    This can more clearly be written like so if you’re using Groovy (or Java 7) for multi-line strings:

    ^\\(?x:
        (?<command>login) \s+ (?<param>\w+)   # Commands that require a parameter
        |                                     # -or-
        (?<command>status|logout) (?<param>)  # Commands that do not require a parameter
    )$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such piece of code. I have 4 sets of checkboxes on a
I have such enum: public enum PartnershipIndicator { VENDOR(VENDOR), COPARTNER(COPARTNER), BUYER(BUYER); String code; private
I have such jquery code: $(.quantity).blur(function() { console.log(upd); $.ajax({ url: /line_items/update_quantity/, type: GET, data:
I have such code(I try to open documents from cloud): NSPredicate *pred = [NSPredicate
I have such code for sending to order my ware. My link in browser
I have such an issue var url = index.php?id=123&sid=321; $.ajax({ type: POST, url: some.php,
Did anybody face to such issue? I have CKEditor completely installed and worked BUT
Good day everyone, i have faced with such an issue as linkage error like
I have rows such as [ISSUE] This is a sample issue [WEBSITE] A bug
Hi!I have used UIBarButton Image but i have got such kind of issue.i mean

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.