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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:05:09+00:00 2026-06-05T16:05:09+00:00

I’m trying to get matches for commands like this; [AUTR| <version_software> | <version_protocol> |

  • 0

I’m trying to get matches for commands like this;

[AUTR| <version_software> | <version_protocol> | <msg> ]
[PING]

What is the regular expression that find this matches for the first command?

AUTR
version_software
version_protocol
msg

this is the code that parse that:

String[] tokens =  msg.replace('<',' ').replace('>',' ').replace('[', ' ').replace(']', ' ').split("\\|");
for (int i=0; i<tokens.length; i++) tokens[i] = tokens[i].trim();

I’m only wondering how it can be done with a regex solution.

EDIT:

I’m trying to match groups with easier expressions, and with this code the call to m.groupCount returns one… but when I try to print it… it throws this exception “java.lang.IllegalStateException: No match found”

    Pattern pattern = Pattern.compile("([\\w+])");
    Matcher m = pattern.matcher("[AUTR]");

    for (int i=0; i<m.groupCount();i++)
    {
        System.out.println(m.group(i));
    } 
  • 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-05T16:05:11+00:00Added an answer on June 5, 2026 at 4:05 pm

    EDIT:
    http://fiddle.re/6ykc

    Regular Expression:

    \[([\w]+)(\s*\|\s*<([\w. ]+)>\s*)*\]
    

    Java Regex String:

    "\\[([\\w]+)(\\s*\\|\\s*<([\\w. ]+)>\\s*)*\\]"
    

    Note that this is for variable commands now and that all extra parameters must match the following character set [a-zA-Z_0-9. ] (Includes periods and spaces).

    Issue: There is an issue with variable length commands that you cannot capture more than one group with a variable type grouping.

    The captured input associated with a group is always the subsequence that the group most recently matched. If a group is evaluated a second time because of quantification then its previously-captured value, if any, will be retained if the second evaluation fails. Matching the string “aba” against the expression (a(b)?)+, for example, leaves group two set to “b”. All captured input is discarded at the beginning of each match.
    http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#cg

    EDIT 2:

    In order to get all of them you can do 2 regular expressions, one to grab the command:

    String command_regex = "\\[([\\w]+)";
    

    And find that and then find the parameters which you can use the <> as your key character to select:

    String parameters = "<([\\w. ]+)>";
    
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(string_to_match);
    
    while (matcher.find()) {
        System.out.println(matcher.group());
    }
    

    Hope that helps.


    ORIGINAL:

    Not exactly sure on the formatting, are the “<” and “>” and “|” required? And what are the formats for the command, version_software, version_protocol and message? This is my attempt though for regular expressions (tested in Python)

    \[(\w+)\s*\|\s*<([\w.]+)>\s*\|\s*<(\w+)>\s*\|\s*<([\w\s]+)>\s*\]
    

    You need to make sure to escape the brackets and the pipe symbols (I added \s* conditions between because I don’t know if there will be spaces or not. If you do:

    >> search.re("expression above", line) 
    >> search.groups()
    

    It should give all tokens in python at least. I left it more hardcoded to allow room for adjustments on each token you wanted to grab, otherwise you could reduce the last 3 parts by making it a group and saying to repeat 3 times. Let me know results?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.