CyberChef
CyberChef copied to clipboard
Operation request: Trim start/end matching a character
Summary
Often I need to trim the start or end of a string, eg. to strip leading/trailing quotes or newlines. This doesn't seem to be an operation yet.
This can currently be roughly emulated with Drop_bytes(0,1,false)Drop_bytes(-1,1,false)
, but this isn't as flexible.
Example Input
aaabbbccc
Example Output
When trimming text a
: bbbccc
When trimming text c
: aaabbb
When trimming regex [a|c]{2}
: abbbc
Ill do this
You can do a fascimile of this using the 'Find / Replace' functionality:
https://gchq.github.io/CyberChef/#recipe=Find_/_Replace(%7B'option':'Regex','string':'(%5Ea*)%7C(a*$)'%7D,'',true,false,true,false)&input=YWFhYWFiYmJjY2NhYWFhYWFh
The regex used is:
(^a*)|(a*$)
Similarly, some other examples:
(^\s*)|(\s*$) # remove whitespace
(^[a|c]{2}*)|([a|c]{2}$) # trim exactly two characters if they are a or c.