Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT</strong>: <a href="http://fiddle.re/6ykc" rel="nofollow">http://fiddle.re/6ykc</a></p> <p>Regular Expression:</p> <pre><code>\[([\w]+)(\s*\|\s*&lt;([\w. ]+)&gt;\s*)*\] </code></pre> <p>Java Regex String:</p> <pre><code>"\\[([\\w]+)(\\s*\\|\\s*&lt;([\\w. ]+)&gt;\\s*)*\\]" </code></pre> <p>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).</p> <p><strong>Issue:</strong> There is an issue with variable length commands that you cannot capture more than one group with a variable type grouping.</p> <blockquote> <p>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. <a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#cg" rel="nofollow">http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#cg</a></p> </blockquote> <p><strong>EDIT 2:</strong></p> <p>In order to get all of them you can do 2 regular expressions, one to grab the command:</p> <pre><code>String command_regex = "\\[([\\w]+)"; </code></pre> <p>And find that and then find the parameters which you can use the &lt;> as your key character to select:</p> <pre><code>String parameters = "&lt;([\\w. ]+)&gt;"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string_to_match); while (matcher.find()) { System.out.println(matcher.group()); } </code></pre> <p>Hope that helps.</p> <hr> <p><strong>ORIGINAL</strong>:</p> <p>Not exactly sure on the formatting, are the "&lt;" 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)</p> <pre><code>\[(\w+)\s*\|\s*&lt;([\w.]+)&gt;\s*\|\s*&lt;(\w+)&gt;\s*\|\s*&lt;([\w\s]+)&gt;\s*\] </code></pre> <p>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:</p> <pre><code>&gt;&gt; search.re("expression above", line) &gt;&gt; search.groups() </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload