Hello, Fletcher,

Thanks!  It's a big improvement over my original.  However, it's still not 
quite 100% there.  Couple things: 

1.  I need it to change "THE" and "The" to "the" (and the same for all of 
the other words that I listed).  Currently, it leaves lower-case "the" 
uncapitalized, which is good, but it completely ignores "THE" and "The."

2.  If one of the listed words happens to be the first or last word of a 
string, it should be capitalized. 

Thanks again!  I hope that many others can benefit from this, too.

Michelle



On Tuesday, October 20, 2015 at 10:21:33 PM UTC-7, [email protected] wrote:
>
> I found a regular expression online and adapted it for BBEdit. If you 
> replace the else conditional of your script with this it seems to work. 
>
> tell application "BBEdit" 
>   tell window 1 
>     if (selection as text) is "" then 
>       set cursorPoint to characterOffset of selection 
>       find "\\b\\w" options {search mode:grep, backwards:true} with 
> selecting match 
>       set selection to (grep substitution of "\\U&") 
>       select insertion point before character cursorPoint 
>     else 
>       replace 
> "\\b(a)(?!(nd?|s|t)?\\b)|\\b(b)(?!(ut|y)?\\b)|\\b(f)(?!(or|rom)?\\b)|\\b(i)\\b|\\b(i)(?!(n|nto|t)?\\b)|\\b(n)(?!(or)?\\b)|\\b(o)(?!(f|n|nto|r)?\\b)|\\b(s)(?!(o)?\\b)|\\b(t)(?!(he|o)?\\b)|\\b(w)(?!(ith)?\\b)|\\b([^abfinostw])(?!\\b)"
>  
> using "\\u\\0" options {search mode:grep} searching in selection 
>     end if 
>   end tell 
> end tell 
>
> The find pattern is kind of a bear, but it breaks down to selecting the 
> first letter of a word which is not equal to one of the items in your list. 
> You can use this directly in BBEdit and then it's double escaped in the 
> AppleScript above. For example, it selects an "a" which starts a word and 
> is not followed by "n", "nd", "s", or "t", a "b" which starts a word and is 
> not followed by "ut" or "y", etc. 
>
> \b(a)(?!(nd?|s|t)?\b)|\b(b)(?!(ut|y)?\b)|\b(f)(?!(or|rom)?\b)|\b(i)\b|\b(i)(?!(n|nto|t)?\b)|\b(n)(?!(or)?\b)|\b(o)(?!(f|n|nto|r)?\b)|\b(s)(?!(o)?\b)|\b(t)(?!(he|o)?\b)|\b(w)(?!(ith)?\b)|\b([^abfinostw])(?!\b)
>  
>
>
> The replacement pattern is \u\0 which changes the found character to 
> uppercase. 
>
> The regex pattern I adapted can be found here, but it uses a different 
> engine than BBEdit and didn't code quite the same list of words. 
>
> http://indesignsecrets.com/grep-solution-to-flawed-title-case-feature.php 
> <http://www.google.com/url?q=http%3A%2F%2Findesignsecrets.com%2Fgrep-solution-to-flawed-title-case-feature.php&sa=D&sntz=1&usg=AFQjCNHwWf_wBasrURjqoZf-4lO_HtZpWw>
>  
>
> [fletcher] 
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" 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 [email protected].
To post to this group, send email to [email protected].

Reply via email to