OK folks, I feel like I'm nearly there, but I have a small outstanding 
issue that perhaps you can find it in your heart to help me with.

To recap. I'm trying to write an all-encompassing script that converts 
IOS/Xcode localisation files to Android's format. This includes the strings 
as well as comment lines. 
Examples of rows:

*IOS:*
/* LOGIN */
"login_welcome" = "Welcome to My app";

*ANDROID:*
<!-- LOGIN -->
<string name="login_welcome">Welcome to My App</string>

*CURRENT SCRIPT, BASED ON YOU COOL GUYS GREAT FEEDBACK:*

*tell* *application* "BBEdit"

*tell* *front* *text window*

*replace* "(\"[^\"]+?\") = \"([^\"]+?)\";" using "<string 
name=\\1>\\2</string>" options ¬

{search mode:*grep*, case sensitive:*false*, starting at top:*true*} -- 
RegEx replacement.

*replace* "/\\*([^*]*?)\\*/" using "<!--\\1-->" options ¬

{search mode:*grep*, case sensitive:*false*, starting at top:*true*}

*replace* "%@" using "%1$s" options {case sensitive:*false*, starting at top
:*true*} -- Literal replacement.

*end* *tell*

*end* *tell*


OK, but I have one outstanding issue.

What I would like is take *everything* between the last to quote signs as 
the body of the xml node. However, it doesn't work with escaped characters.


As an example, if I take the above row and change it to

"login_welcome" = "Welcome to \"My App\" "; - it doesn't work. 


What I would like is basically "between quote one and two, use in <string 
name="">, then everything between quote number three and the ending ' "; ' 
use as body, then end with </string>.


Does this name sense?






lördag 18 mars 2023 kl. 21:24:40 UTC+1 skrev Kaveh Bazargan:

> All sounds good Mathias. I miss AppleScript. I wrote a lot of it to help 
> editing videos. It's just that grep is hard to read as it is!!
>
> Perhaps not relevant, but I recently found Text Factory in BBEdit that 
> lets you string lots of greps together...
>
> Regards
> Kaveh
>
> On Sat, 18 Mar 2023 at 11:45, Mathias <[email protected]> wrote:
>
>> Huge thanks Bruce. You guys are insane at grep'ing, sed'ing etc. The 
>> answers I've gotten in here are like machine code sometimes. :)
>>
>> Kaveh, the reason I use AppleScript is because I've used it outside 
>> BBEdit in the past, so I'm most familiar with that setup. I've gotten solid 
>> evidence in here previously that it's probably not the best tool for the 
>> job, but when you deal with this stuff once every three years you kind of 
>> don't have time to learn something new... (I probably should I guess). 
>> Again, thanks.
>>
>> fredag 17 mars 2023 kl. 16:18:21 UTC+1 skrev Kaveh Bazargan:
>>
>>> Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot 
>>> of AppleScript in the past but no regex in that. 
>>>
>>> It's just that the extra escape and all the verbosity in AppleScript 
>>> makes it painful to decode!
>>>
>>> On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen <[email protected]> wrote:
>>>
>>>> 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
>>>> .
>>>>
>>>
>>>
>>> -- 
>>> Kaveh Bazargan PhD
>>> Director
>>> River Valley Technologies <http://rivervalley.io> ● Twitter 
>>> <https://twitter.com/rivervalley1000> ● LinkedIn 
>>> <https://www.linkedin.com/in/bazargankaveh/> ● ORCID 
>>> <https://orcid.org/0000-0002-1414-9098> ● @[email protected] 
>>> <https://mastodon.social/@kaveh1000>
>>> *Accelerating the Communication of Research*
>>>
>>> * 
>>> <https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>
>>>    
>>> <https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop>*
>>>
>> -- 
>> 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/3199598c-4f6c-4d5e-8ca2-03d81dea5b6fn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/bbedit/3199598c-4f6c-4d5e-8ca2-03d81dea5b6fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Kaveh Bazargan PhD
> Director
> River Valley Technologies <http://rivervalley.io> ● Twitter 
> <https://twitter.com/rivervalley1000> ● LinkedIn 
> <https://www.linkedin.com/in/bazargankaveh/> ● ORCID 
> <https://orcid.org/0000-0002-1414-9098> ● @[email protected] 
> <https://mastodon.social/@kaveh1000>
> *Accelerating the Communication of Research*
>
> * 
> <https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>
>    
> <https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop>*
>

-- 
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/9ed9f458-90fe-43f0-98b4-1a491e67d6b4n%40googlegroups.com.

Reply via email to