public
static
String
delRepeatSym1
(
String
str
)
{
if
(
StringUtils
.
isEmpty
(
str
)
)
{
return
""
;
Pattern
compile
=
compile
(
"[,。!\\”\\?]"
)
;
StringBuffer
content
=
new
StringBuffer
(
)
;
AtomicInteger
index
=
new
AtomicInteger
(
0
)
;
char
[
]
contentChars
=
str
.
toCharArray
(
)
;
for
(
int
i
=
0
;
i
<
contentChars
.
length
;
i
++
)
{
String
curStr
=
String
.
valueOf
(
contentChars
[
i
]
)
;
Matcher
matcher
=
compile
.
matcher
(
curStr
)
;
boolean
del
=
matcher
.
find
(
)
;
content
.
append
(
curStr
)
;
if
(
del
&&
i
>
0
)
{
String
strPre
=
String
.
valueOf
(
contentChars
[
i
-
1
]
)
;
Matcher
matcherPre
=
compile
.
matcher
(
strPre
)
;
if
(
matcherPre
.
find
(
)
)
{
content
.
deleteCharAt
(
i
-
index
.
getAndIncrement
(
)
)
;
return
content
.
toString
(
)
;
public
static
void
main
(
String
[
]
args
)
{
String
content
=
"欢迎阅读【字符串操作-正则】-文本字符串中多余重复出现的标点符号截取最后一个的文章,,多多点赞。。谢谢!!。"
;
String
result
=
delRepeatSym1
(
content
)
;
System
.
out
.
println
(
result
)
;
-
用到真正表达式配置标点符号
-
通过
StringBuffer
在遍历中重新拼接,没有通过记录重复的下标,再次遍历del重复的数据
-
注意重新拼接,
deleteCharAt
后的越界问题
1、逗号分隔
中
英文
字符串
,不能在首尾
出现
,
中
间有且仅有
一个
逗号
const reg = /^(?!,)(?!.*,$)[\u4e00-\u9fa5a-zA-Z]+(?:[,][\u4e00-\u9fa5a-zA-Z]+)*$/g;
const reg = /^(?!,)(?!.*,$)[\u4e00-\u9fa5a-zA-Z]+(?:[,][\u4e00-\u9fa5a-zA-Z]+)*$/g;
if (reg.test(value)) {
callback();
public static void main(String[] args) {
String str = "group-banner-top-http://pic/test/20220225092606e0dc59c3ef8c915b8fbe9f99153b7ef9";
//获取第
一个
"-"后面的所有
字符串
int index = str.indexOf("-");
System.out
def remove_punctuation(text):
# 匹配
中
英文
标点符号
punctuation_pattern = re.compile('[^\u4e00-\u9fa5^a-z^A-Z^0-9]')
# 将匹配到的
标点符号
替换为空格
text = punctuation_pattern.sub(' ', text)
# 去除
多余
的空格
text = re.sub('\s+', ' ', text).strip()
return text
text = '这是一段只含有
中
英文
标点符号
的
字符串
,需要去除。'
text = remove_punctuation(text)
print(text)
输出结果为:这是一段只含有
中
英文
标点符号
的
字符串
需要去除
IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效
41730
IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效
newzhong1:
IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效
IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效
敲代码的ikun:
IDEA配置xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)解决方法,亲测有效
dark_corrupt: