[英]Splitting a string on dot (.) except if it appears in a fraction using regex in Java
As the title says, I want to split a string using java regex based on dot but only if the dot appears in between alphabets.正如标题所说,我想使用基于点的 java regex 拆分字符串,但前提是点出现在字母之间。
Lets say the string is:假设字符串是:
System.out.println(5.55);
I need output as我需要输出为
System
out
println(5.55);
A lookbehind and lookahead for letters is probably what you want.字母的后视和前瞻可能是您想要的。 DEMO
演示
(?<=[a-zA-Z])\.(?=[a-zA-Z])
String content = "asdf.qweflkjasdf.qweflasdfasfd55.523";
Pattern p = Pattern.compile("(?<=[a-zA-Z])\\.(?=[a-zA-Z])");
System.out.println(p.matcher(content).replaceAll("\n"));
OUTPUT:
asdf
qweflkjasdf
qweflasdfasfd55.523
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.