The simpler answer is to use the Text > Entab... command. This will generally 
do the replace you want although it doesn't strictly follow the replace spaces 
only at the start of a line rule. The Text > Detab... command will replace tabs 
with spaces.

You can do this with a regular expression as well. First, if you want to find 
four of a character you can do "a{4}" rather than "aaaa". And then since you 
don't want to replace the tabs at the beginning of the line you can use a 
look-behind assertion to make sure you are at the start of a line. The 
look-behind assertion (?<=[\r\t])a would match an a only if it occurred 
immediately after a return or tab. In order to get spaces which might be the 
first characters in the file we need to switch this around (?<![^\r\t])a is a 
negative look-behind assertion that does the same thing, but also matches the 
start of the file.

Find: (?<![^\r\t]) {4}
Replace: \t

[fletcher]
 
> On Feb 25, 2016, at 12:05 PM, Brian Porter <bepor...@gmail.com> wrote:
> 
> I'm trying to find a trick for using the grep-enabled Find/Replace BBEdit to 
> convert files that use spaces for indentation to using tabs. Here's an 
> example input text snippet:
> 
>     1. Item
>         a. sub-item
>             i. third level
>             ii. another third level
>     2. Second Top Level
> 
> 
> What I'd like to do is replace all sets-of-4-spaces at the beginning of the 
> line with a single tab (per each 4-space-set), but it seems like this would 
> require being able to count the number of matches and use that in the back 
> reference somehow
> 
> For example, the following search and replace patterns can be used to replace 
> the first set of spaces with a tab, but this pattern must be applied 
> repeatedly for every "level" of indent being used in the file:
> 
> Find:
> ^(\t*)(\ \ \ \ )
> 
> Replace:
> \1\t
> 
> 
> Ideally I want something like this:
> 
> Find:
> ^((\ \ \ \ )+)
> 
> Replace:
> \t{countOf(\2 in \1)}    # Yes it's wildly invalid; use your imagination. :-P
> 
> 
> I'm unaware of any mechanism in grep/regex that would allow for this. Am I 
> correct in thinking it's impossible? Is there an alternative approach, 
> perhaps via Apple/shell script that could get the job done that I'm not 
> considering?
> 
> Thanks,
> Brian
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a 
> feature request or would like to report a problem, please email
> "supp...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit 
> <http://www.twitter.com/bbedit>>
> 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to bbedit+unsubscr...@googlegroups.com 
> <mailto:bbedit+unsubscr...@googlegroups.com>.
> To post to this group, send email to bbedit@googlegroups.com 
> <mailto:bbedit@googlegroups.com>.

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.

Reply via email to