[英]Comparing a String with a template like string
I am trying to write a program in which I have to do comparison between a list of strings with a template (which is essentially a string). 我正在尝试编写一个程序,我必须在其中对一个字符串列表与模板(实际上是一个字符串)进行比较。 I am not sure what is the term used but it is going to be more of log scraping program if that helps.
我不确定使用的术语是什么,但如果有帮助的话,它将更多的是日志抓取程序。
Input String Examples: 输入字符串示例:
To be compared against 要比较
a. 一种。 This is a ?
这是一个? file
文件
b. 湾 Hello World this is ?
你好世界这是?
The idea is to match input statements (1-4) against template strings (ab) and if they match then I need to act on them. 我们的想法是将输入语句(1-4)与模板字符串(ab)进行匹配,如果它们匹配,那么我需要对它们进行操作。 Like 1 & 4 match sentence b but 2 does not.
像1和4匹配句子b但是2没有。
Thanks in advance for help/directions. 在此先感谢您的帮助/指示。
Change your ?
改变你的
?
to .*
and you've got a regex: to
.*
你有一个正则表达式:
String input = "Hello World this is me";
if (input.matches("Hello World this is .*"))
// true
etc 等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.