是否可以使用正则表达式测试 JPA/EJB QL 语句?
我不是正则表达式方面的专家,所以我想我应该抛出这个问题。我认为正则表达式可以帮助我的测试更加健壮(测试生成的 EJB QL 语句是否正确生成)。
例如:
select u.firstName, u.lastName from Users u where u.age > 50
我使用什么正则表达式将其拆分为以下内容?
- "u.firstName, u.lastName"
- "Users u"
- "u.age > 50"
无论关键字的大小写(即 SELECT、Select、select...),也无论前后可能有空格关键词?当然,进一步拆分它会更好,但是如果我可以像上面的示例那样拆分部分,我可以改进我的测试。
预先感谢您的任何指示和帮助。
I'm not an expert on regular expressions so I thought I'd throw this question out. I'm thinking regular expressions can help make my tests more robust (testing generated EJB QL statements for correct generation).
For example:
select u.firstName, u.lastName from Users u where u.age > 50
What regex do I use to split it into the following?
- "u.firstName, u.lastName"
- "Users u"
- "u.age > 50"
regardless of the case of the keywords (i.e. SELECT, Select, select, ...) and regardless of the possible spaces before and after the keywords? Of course it would be even better to split it further, but if I can split parts as above example, I can improve my tests.
Thanks in advance for any pointers and help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要拆分的正则表达式类似于:
您可以使用语言工具将正则表达式编译为不区分大小写
The regex to split would be something like:
you can use the lanaguage s tool to compile regex to be non case sensitive
最简单的正则表达式类似于:
根据您的语言,您应该能够为正则表达式设置不区分大小写的标志。其结果将是 3 个捕获组,其中包含所需信息(由空格包围)。使用
trim()
或您语言中的类似函数来去除不需要的空格而不是使正则表达式变得更复杂会更容易。The easiest regex would be something like:
Depending on your language you should be able to set flags for regex to be case insensitive. The result of it will be 3 captured groups that contain required information (surrounded by spaces). It would be easier just to use
trim()
or similar function in your language to strip unneded spaces rather than making regex more complex.