gpt4 book ai didi

java - 删除 String 中除某些符号之外的所有符号

转载 作者:行者123 更新时间:2023-12-01 11:20:23 25 4
gpt4 key购买 nike

我需要删除 String 中除 () 之外的所有符号,但我不知道如何编写正确的 Regex 模式 和然后使用 .removeAll() 方法。

示例

一些文本(some 1 text())和(some 2 text) -> (())()

最佳答案

如果您想使用搜索功能,您可以使用以下正则表达式:

[()]

查看演示 https://regex101.com/r//

如果您想使用替换函数,您可以将以下正则表达式替换为空字符串:

[^()]

关于java - 删除 String 中除某些符号之外的所有符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31311746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com