ANTLR3:确保该字符至少出现在一个地方
我试图确保带有通配符的文本中至少包含一个字符,
fragment CHARACTER : ('a'..'z'|'0'..'9'|'-'|'&'|'@'|'$'|'%'|'.'|':');
fragment WILDCARD_QUESTION : ('?');
WILD_STRING
: (CHARACTER)*
(
(WILDCARD_QUESTION)
(CHARACTER)*
)+;
即使使用一个?在我希望失败的地方被接受。因此,仅应传递至少一个字符的序列。
我需要的是 a?
、?a
、?a?
、a?a
等通过。只有 ?
、??
等应该失败。即应该至少有一个字符而不仅仅是WILDCARD_QUESTION。该字符可以位于通配符的任一侧。
I am trying to ensure that at least one character is included in the text with wildcards
fragment CHARACTER : ('a'..'z'|'0'..'9'|'-'|'&'|'@'|'
Using this even a single ? gets accepted where as I would like it to fail. So only sequences that that at least one character should be passed.
What I need is for a?
, ?a
, ?a?
, a?a
etc to pass. Only ?
, ??
etc should fail. ie there should be at least one character and not just WILDCARD_QUESTION. The character can be on either side of the wildcard.
|'%'|'.'|':');
fragment WILDCARD_QUESTION : ('?');
WILD_STRING
: (CHARACTER)*
(
(WILDCARD_QUESTION)
(CHARACTER)*
)+;
Using this even a single ? gets accepted where as I would like it to fail. So only sequences that that at least one character should be passed.
What I need is for a?
, ?a
, ?a?
, a?a
etc to pass. Only ?
, ??
etc should fail. ie there should be at least one character and not just WILDCARD_QUESTION. The character can be on either side of the wildcard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用两条规则来执行此操作,一条用于前导通配符,另一条用于前导字符:
Do it with two rules, one for leading WILDCARDs and one for leading CHARACTERs:
更改代码以读取
这似乎可以解决问题。
Changed code to read
This seems to solve the issue.