Java Regex删除开始/结束单引号,但留下引号 [英] Java Regex to remove start/end single quotes but leave inside quotes
本文介绍了Java Regex删除开始/结束单引号,但留下引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以单引号括起来的CSV文件中的数据,例如:
I have data from a CSV file that is enclosed in single quotes, like:
'Company name'
'Price: $43.50'
'New York, New York'
能够替换值的开始/结束处的单引号,但在数据中留下引号,例如:
I want to be able to replace the single quotes at the start/end of the value but leave quotes in the data, like:
'Joe's Diner' should become Joe's Diner
我可以做
updateString = theString.replace("^'", "").replace("'$", "");
但我想知道我是否可以结合它只做一个替换。
but I wanted to know if I could combine it to only do one replace.
推荐答案
您可以使用或运算符。
updateString = theString.replaceAll("(^')|('$)","");
查看是否适用于您:)
这篇关于Java Regex删除开始/结束单引号,但留下引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文