gpt4 book ai didi

用于从查询字符串中删除参数的 Java 正则表达式模式

转载 作者:搜寻专家 更新时间:2023-10-31 08:09:19 24 4
gpt4 key购买 nike

我正在寻找从 Java 中所有可能的以下查询字符串中删除 foo 参数及其值的方法。

是否有正则表达式模式可以执行此操作?

http://localhost/test?foo=abc&foobar=def 
http://localhost/test?foobar=def&foo=abc
http://localhost/test?foo=abc
http://localhost/test?foobar=def&foo=abc&foobar2=def

结果字符串将是

http://localhost/test?foobar=def 
http://localhost/test?foobar=def
http://localhost/test
http://localhost/test?foobar=def&foobar2=def

最佳答案

此正则表达式应匹配 GET 参数及其值...

(?<=[?&;])foo=.*?($|[&;])

RegExr .

只需将其替换为空字符串即可。

关于用于从查询字符串中删除参数的 Java 正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9191327/

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