简体   繁体   English

将正则表达式转换为特殊字符

[英]Convert regex to special characters

I have a url that would contain something like this: 我有一个包含以下内容的网址:

%5B%7B%22field%22%3A%22Site+Code%22%2C%22value%22%3A%2245%22%7D%2C%7B%22field%22%3A%22textarea-1%22%2C%22value%22%3A%2212%22%7D%2C%7B%22field%22%3A%22Serial+%23%22%2C%22value%22%3A%2223%22%7D%5D%26SiteID%3D1%3B

I'm taking in the url as a string and would like to convert all the regex to special characters. 我将url作为字符串输入,并希望将所有正则表达式转换为特殊字符。 Is there any way to do this? 有什么办法吗? The regex is not limited to just this. 正则表达式不仅限于此。 I need to take into account all instances in which regex could show up in the string, and replace it with the corresponding special character. 我需要考虑所有可能在字符串中显示正则表达式的实例,并用相应的特殊字符替换它。

Since there are so many special characters you will need to account for, and in regex you will have to replace each one seperately, I do not think that regex is the best solution to this issue. 由于您需要考虑很多特殊字符,而在regex中,您将不得不单独替换每个字符,因此我认为regex不是解决此问题的最佳解决方案。 A better solution is available here: How to do URL decoding in Java? 这里有一个更好的解决方案: 如何用Java进行URL解码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM