java - Concatenate multiple commands -
how can manipulate regular expression
string onecmd = "([0-9]+\\.[tcm]{1}\\#.+\\#[wsn]{1})"; to avoid matching
"100.m#testvalue#w100.m#testvalue#w" but allow matching
100.m#testvalue#w ? because in end want there can multiple commands separated |
string regex = "^(" + onecmd + "$|" + onecmd + "\\|{1}" + onecmd + "$)"; so valid commands are:
cmd cmd|cmd1|cmd2|... not ending '|' !! but first problem if concatenate 2 or more commands still valid.
i think readable way first split on | , apply regex allows 1 match:
^[0-9]+\\.[tcm]#[^#]*#[wsn]$ if want find matches separated | and/or start/end of string, can positive lookahead assertions instead of ^ , $ anchors:
(?<=^|\\|)[0-9]+\\.[tcm]#[^#]*#[wsn](?=$|\\|)
Comments
Post a Comment