CyberChef icon indicating copy to clipboard operation
CyberChef copied to clipboard

Operation request: Trim start/end matching a character

Open holly-hacker opened this issue 1 year ago • 2 comments

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

holly-hacker avatar Dec 29 '23 18:12 holly-hacker

Ill do this

mattbrwnn avatar Jan 24 '24 00:01 mattbrwnn

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.

a3957273 avatar Feb 13 '24 11:02 a3957273