Yes, double escapes are needed. As handy as Applescript is, quoting is a major 
pain point.

‘*’ has special meaning within regular expressions, so it must be escaped when 
trying to match a literal ‘*’. So that's the first ‘\’. Then Applescript needs 
that ‘\’ escaped, so we get ‘\\*’.
 
The BBEdit User Manual (PDF download via the Help menu) has a good discussion 
of this.

    — Bruce

_bruce__van_allen__santa_cruz_ca_





> On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan <[email protected]> wrote:
> 
> Quick question: For AppleScript you need to double escape, right? so:
>     • 
> in AppleScript: \\*
>     • becomes \* in BBEdit
>     • to find "*"
> 
> 
> On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen <[email protected]> wrote:
> Oops - I mis-typed one bit: the inner part of the find pattern should be 
> “[^*]” - asterisk instead of plus sign.
> 
> tell application “BBEdit"
>   tell front text window
>     replace "/\\*([^*]*?)\\*/" using "<!--\\1-->" options ¬
> {search mode:grep, case sensitive:false, starting at top:true}
>   end tell
> end tell
> 
> 
>     — Bruce
> 
> _bruce__van_allen__santa_cruz_ca_
> 
> 
> 
> 
> 
> > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen <[email protected]> wrote:
> > 
> > Here’s a slightly amended version of your script:
> > 
> > tell application “BBEdit”
> >  tell front text window
> >    replace "/\\*([^+]*?)\\*/" using "<!--\\1-->" options ¬
> > {search mode:grep, case sensitive:false, starting at top:true}
> >  end tell
> > end tell
> > 
> > The differences are:
> > 
> > - no parentheses () surrounding the whole find pattern because that becomes 
> > the first capture, which you use in the replacement pattern as ‘\1’.
> > 
> > - added parens around the inner part of the find pattern, in order to 
> > capture what’s between the JS comment markers.
> > 
> > -  if you needed to keep that outer parens capture for some other reason, 
> > then change the replacement pattern to “<!—\\2—>” (assuming that part stays 
> > the second parens-capture).
> > 
> > - I omitted the replace “%@“ line to keep this part of the script clear.
> > 
> > Using the script as I wrote it above
> > 
> > /* some commented stuff */ /*some more*/
> > 
> > And /* some more*/
> > 
> > is transformed in one step into 
> > 
> > <!-- some commented stuff --> <!--some more-->
> > 
> > And <!-- some more-->
> > 
> > 
> > HTH
> > 
> >    — Bruce
> > 
> > _bruce__van_allen__santa_cruz_ca_
> > 
> > 
> > 
> > 
> > 
> >> On Mar 17, 2023, at 3:04 AM, Mathias <[email protected]> wrote:
> >> 
> >> OK, so I'm working on an apple script to replace Localizable (apple) 
> >> comments on the /* ... */ format to <!-- and -->
> >> 
> >> I got it working, but I'm using two commands because I couldn't figure the 
> >> grep out... can this be simplified with only one "replace" ? 
> >> 
> >> pointers appreciated, script here:
> >> 
> >> tell application "BBEdit"
> >> tell front text window
> >> replace "(/\\*[^\\*]*\\*/)" using "<!--\\1-->" options ¬
> >> {search mode:grep, case sensitive:false, starting at top:true} 
> >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case 
> >> sensitive:false, starting at top:true} 
> >> replace "%@" using "%1$s" options {case sensitive:false, starting at 
> >> top:true} 
> >> 
> >> end tell
> >> end tell
> >> 
> >> -- 
> >> This is the BBEdit Talk public discussion group. If you have a feature 
> >> request or need technical support, please email "[email protected]" 
> >> rather than posting here. Follow @bbedit on Twitter: 
> >> <https://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 view this discussion on the web visit 
> >> https://groups.google.com/d/msgid/bbedit/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.com.
> > 
> > -- 
> > This is the BBEdit Talk public discussion group. If you have a feature 
> > request or need technical support, please email "[email protected]" 
> > rather than posting here. Follow @bbedit on Twitter: 
> > <https://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 view this discussion on the web visit 
> > https://groups.google.com/d/msgid/bbedit/B37085B8-A95C-4105-B396-5E089AADFEFB%40cruzio.com.
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a feature 
> request or need technical support, please email "[email protected]" 
> rather than posting here. Follow @bbedit on Twitter: 
> <https://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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/B4B02A99-8F77-4877-93AD-328302B74BBB%40cruzio.com.
> 
> 
> -- 
> Kaveh Bazargan PhD
> Director
> River Valley Technologies ● Twitter ● LinkedIn ● ORCID ● 
> @[email protected]
> Accelerating the Communication of Research
>   
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a feature 
> request or need technical support, please email "[email protected]" 
> rather than posting here. Follow @bbedit on Twitter: 
> <https://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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/CAJ2R9pgTRLttsekBAWXHFUW7NUFRcH%2BbhOEjDpsr3axsXEQhGA%40mail.gmail.com.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/51834A85-668C-4A18-903C-3DCA88FD83A3%40cruzio.com.

Reply via email to