Regex is great for massaging data into the form you want to input into another program.
One case I often have is long lists of output from a PHP script using
var_dump()
which I want to paste into an Excel spreadsheet. But I need to remove the preceding "string '" and the trailing "' (length=<length of string>)" for the data to make sense.To remove the starting "string '", just use a normal search (since the string is the same on all lines). To remove the ending we need to use regex since the <length of string> value can vary, using the regular expression search
\' \(length=.*
should do the trick.
No comments:
Post a Comment