Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将正则表达式与行尾匹配?_Java_Regex - Fatal编程技术网

Java 如何将正则表达式与行尾匹配?

Java 如何将正则表达式与行尾匹配?,java,regex,Java,Regex,我正在尝试编写一个正则表达式,它执行以下操作: -查找至少一个=,并将这些=带到1)行尾或2)一个点 正则表达式: [=]+?[=]+.*?[.$]+ 测试字符串: b == 123 //does not match, but which should as it is end of line! b == 123. //does match "== 123.", which is OK b == 123.abc //does match "== 123.", which is OK 我在这里用

我正在尝试编写一个正则表达式,它执行以下操作: -查找至少一个
=
,并将这些
=
带到1)行尾或2)一个点

正则表达式:

[=]+?[=]+.*?[.$]+

测试字符串:

b == 123 //does not match, but which should as it is end of line!
b == 123. //does match "== 123.", which is OK
b == 123.abc //does match "== 123.", which is OK
我在这里用endofline
$
锚缺少什么?

[.$]
表示一个由点或美元符号组成的符号。如果您想要正则表达式元素之间的替代项,即
(\.\124;$)

此外,您可以使用
[^…]
而不是
.*?

([^=]+)=+([^.]+)(?:\.|$)