正如问题所说,我想知道您是否可以在所有匹配的末尾或仅在某些匹配的末尾添加一个空格字符
我有一个正则表达式代码
${Brand Name}${Colour}${Product Description}${ID}它吐出来的是什么
Facille SnapBlackTablestop Snapkin Dispenser and Pack of Snapkins4696400
Brand Name: Facille Snap
Colour: Black
Product Description: Tablestop Snapkin Dispenser and Pack of Snapkins
ID: 4696400我希望regex返回一个可用的文本行,如下所示
Facille Snap - Black Tablestop Snapkin Dispenser and Pack of Snapkins - 4696400发布于 2012-08-21 01:40:52
在我看来,这些不像正则表达式。
根据评论,您可能希望使用以下代码:
${Brand Name} ${Colour} ${Product Description} - ${ID}
除此之外,您还可以像这样拆分CamelCase文本:
System.out.println(camelSplit("ThisIsAFunkyCamelString"));
/** Returns a copy of s with a space in front of each capital letter. */
public String camelSplit(String s) {
if (s == null || s.length < 2) {
return s;
}
return s.substring(0, 1) + s.substring(1).replaceAll("([A-Z])", " $1");
}注意:上面的方法假设每个大写字母前面都要加一个空格。如果你想让它处理像USA这样的缩写词,你必须添加更多的逻辑。
https://stackoverflow.com/questions/12042217
复制相似问题