我正在使用Java.我需要使用正则表达式解析以下行:
<actions>::=<action><action>|X|<game>|alpha
Run Code Online (Sandbox Code Playgroud)
这应该给我的标记<action>,<action>,X和<game>
什么样的正则表达式会起作用?
我正在尝试...... "<[a-zA-Z]>"但是这并没有照顾X或alpha.
你可以尝试这样的事情:
String str="<actions>::=<action><action>|X|<game>|alpha";
str=str.split("=")[1];
Pattern pattern = Pattern.compile("<.*?>|\\|.*?\\|");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group());
}
Run Code Online (Sandbox Code Playgroud)