$data
contains tabs, leading spaces and multiple spaces. I wish to replace all tabs with a space. Multiple spaces with one single space, and remove leading spaces.
In fact somthing that would turn this input data:
[ asdf asdf asdf asdf ]
Into output data:
[asdf asdf asdf asdf]
How do I do this?
In python string literals, the '\t' pair represents the tab character. So you would use mystring. replace('\t', 'any other string that you want to replace the tab with') .
You can simply use this regular expression to replace any type of escapes( including tabs, newlines, spaces etc.) within a String with the desired one: lineOfText. replaceAll("\\s", " ");
Trim, replace tabs and extra spaces with single spaces:
$data = preg_replace('/[ ]{2,}|[\t]/', ' ', trim($data));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With