正则表达式替换转义字符串中的模式控制字符 [英] Regex replace pattern control characters in escaped string
问题描述
我有一个转义的字符串,其中包含某些控制字符。
控制字符是 ACK
, STX
类型。
参考: http://ascii.cl/control-characters.htm
I have an escaped string that contains certain control characters.
The control characters are the ACK
, STX
types.
Reference: http://ascii.cl/control-characters.htm
我需要用〜
替换所有控制字符,最好是所有连续的控制字符。
I need to replace all the control characters, preferably all consecutive control characters with ~
.
例如输入
%00%00%00%02THE%20QUICK%BROWN%00%00%00%0D%00%00%00%0FFOX%20JUMPED%00%00%00%0EOVER%20THE%00%00%4E%02LAZY%20DOG
我想要的输出应该是:
~THE%20QUICK%20BROWN~FOX%20JUMPED~OVER%20THE~LAZY%20DOG
为了我自己和其他人,我寻找的方法是替换一个模式这种情况类似于%0?%0?%0?%0
??
For the sake of myself and others the method i look for is to replace a pattern which in this case would be something like %0?%0?%0?%0
?? Meaning anything that could creep into the text.
字符串模式
-
字符串的长度应为12
String should be of length 12
字符串应包含4个百分比的零符号,例如。 %0
String should contain 4 percentage zero symbols ex. %0
我也欢迎其他建议
目的是摆脱字符串中的所有控制字符。替换为〜
只是为了保持在哪里替换(调试)的选项卡。
Intention is to get rid of all control characters from the string. Replacing with ~
is just to keep a tab on what got replaced where (debugging).
推荐答案
尝试以下表达式:
(%[0-13-9A-F][0-9A-F])+
它找到重复的控制字符序列,除了%20。
It finds all sequences of control chars repeated, except for %20.
有了它,我得到以下输出:
With it I get this output:
~THE%20QUICK%BROWN~FOX%20JUMPED~OVER%20THE~LAZY%20DOG
这篇关于正则表达式替换转义字符串中的模式控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!