There are a lot of questions about replacing spaces with tabs on here, however this is the first I've come across which needs to limit the replaces to spaces that are before any characters.
So I start with (?: ) (that's 4 spaces)
Which gives me:

However I only want to match the spaces before any words! So I need to ignore the space's after greedy and accept.
So I try the start line operator ^. Giving me ^(?: )
Which only matches 4 spaces directly prefixed with a ^

So I add + to match many, final regex is ^(?: )+, however that gives me:

which matches all spaces between the start ^ and a character, like I want, however the matches are not in groups of four! The colour block spans the whole line, which is wrong!
I need some Regex pro's to explain to me where I'm going wrong!
Should have probably mentioned, I'm not working to any specific regex engine.
I'd rather the solution not use look behinds, but if it has to, it has to.
Here's the text for testing:
output.parents('.datatable-expanded').droppable({
greedy : true,
accept : '.ui-draggable',
tolerance : 'intersect',
hoverClass: 'drop-hover',
drop: function(e, ui) {
self.handleDrop(ui.helper, $(this).parents('tr').prev())
},
});
This one seems to work. It matches the beginning of the string, plus one or more group(s) of 4 spaces.
/\G {4}/g
Example here on regex101
This worked in vscode. It halves the number of spaces that start each line.
Find: ^(( )+)\1
Replace with: $1
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