Re: Noob trying to improve on these grep / expressions

2019-01-04 Thread Dj
Ah! It was your cheatsheet that I have been studying, somehow I didn't 
connect the name here and there. Thankful I asked in the right place, I 
wasn't expecting a masterclass  . I've put what you suggested in notes 
and will use them as a good jumping off point along with your book. 

The last couple things I'm curious about before doing a deeper dive... To 
remove all text between paranthesis (and also the parenthesis), what would 
that expression be? 

How about only extracting the last sentence of each paragraph?   No biggie, 
if that's asking too much, appreciate the time you've given here.

On Friday, January 4, 2019 at 11:10:40 AM UTC-8, Christopher Stone wrote:
>
> On 01/03/2019, at 17:53, Dj > wrote:
>
> Couple more quick things: would it be hard to do one that only extracts 
> text that is within quotation marks?
>
> --
>
> Hey Dj,
>
> Straight-Quotes
>
> "[^"]+?"
>
> Smart-Quotes
>
> “[^”]+?”
>
> I tried one off a github cheatsheet and in the past hours couldn't modify 
> it easy, but am making progress. Also, if you or anyone on here can suggest 
> a book on getting better at expressions and BBedit?
>
>
> See appended document.  I haven't updated it in a while, but it's 
> still relevant.
>
> Maybe just piecing it together off stackoverflow and google etc is best 
> though? Thanks again
>
>
> Not just no but HELL no!  
>
> You can definitely get help with things via this method, but you'll waste 
> a lot of time when working for general education.
>
> You need:
>
> A good basic book.
> A good intermediate book.
> A RegEx recipe book.
> Tools like BBEdit , Patterns 
> 
>  and/or RegExRX 
> .
> An online RegEx analyzer like RegEx101.com 
> Mentoring.
> Lots of practice.
>
> Very basic regular expressions are pretty easy to learn, but advanced 
> usage requires a fair amount of dedicated time and effort.
>
> --
> Best Regards,
> Chris
>
> --
>
> Regular Expressions References and Resources
> by Christopher C. Stone
> 2015/03/20
>
>
> -
> AppleScript-Objective-C Libraries
> -
>
>
> With the advent of Mavericks and AppleScript-Objective-C Libraries it is 
> possible to add regex support to AppleScript via a library.
>
>
> 
> Some Information on Learning Regular Expressions
> 
>
>
> Learning basic regular expressions is relatively easy.  Becoming really 
> good with them takes dedication, a lot of practice, and some tutelage.
>
> The BBEdit & TextWrangler Manuals devote a whole chapter to regular 
> expressions: Searching with Grep (currently chapter 8).  It's a reference 
> rather than a tutorial, but it does explain at least briefly many of the 
> fundamentals.
>
> My cheat-sheet for BBEdit/TextWrangler is up on Gist:
>
> https://gist.github.com/ccstone/5385334
>
> BBEdit/TextWrangler uses PCRE (Perl Compatible Regular Expressions), so 
> it's a pretty decent if not complete reference.
>
>
> ---
> Regex Books
> ---
>
>
> Regex neophytes are better off starting with a book specifically written 
> for beginners.
>
> I have these books (in addition to a couple of tomes on Perl):
>
> "Sams Teach Yourself Regular Expressions in 10 Minutes" by Ben Forta
>
> "Beginning Regular Expressions" by Andrew Watt
>
> "Regular Expressions Cookbook"  by Jan Goyvaerts and Steven Levithan
>
> "Mastering Regular Expressions" by Jeffrey Friedl (Advanced)
>
>
> ---
> Regex Analyzers
> ---
>
>
> Here's a very good on-line regex analyzer with an example:
>
> https://regex101.com/r/oA9mZ4/1
>
> There's a decent little utility available on the App-Store called Patterns 
>  
> that 
> live-updates as you create your pattern. ($2.99)
>
> Another one I like is:
>
> RegExRX 
>
> Mark Alldritt the author of Script Debugger  
> has posted a free one for the iPad:
>
> RegEx Knife 
>
> I've found it very handy to have live feedback when building a complex 
> pattern and wish I'd had something like that when I started learning regex 
> more than 20 years ago.
>
>
> 
> Online Regex Tutorials & Information
> 
>
>
> Extracting a good working knowledge of regular expressions from the 
> Internet is a serious chore.  There are many flavors of regex out there, 
> such as Perl/PCRE, Java, Javascript, Ruby, Python, TCL...
>
> They are all similar, but the differences can be confusing and 
> frustrating.  

Re: Noob trying to improve on these grep / expressions

2019-01-04 Thread F. Alfredo Rego
Thanks, Chris.

I really appreciate (and enjoy) every one of your wise contributions.

Alfredo

> On Jan 4, 2019, at 12:58 PM, Christopher Stone  
> wrote:
> 
> On 01/04/2019, at 13:44, F. Alfredo Rego  > wrote:
>> RegExRX seems to have gone dormant five years ago. 
>> 
>> Do you have any news/updates regarding newer/better approaches, if any?
> 
> 
> Hey Alfredo,
> 
> Crud.  I didn't realize it was a 32-bit app.
> 
> You can find it here:
> 
> http://www.mactechnologies.com/index.php?page=downloads#regexrx 
> 
> And you can drop the developer a note requesting an update.  (I just did.)
> 
> I usually start building a regular expression with BBEdit.
> 
> If I'm having trouble I usually go to Patterns.
> 
> But there are times when RegExRx is better, so I hope the dev gets on his 
> keyboard and drums out some new code.
> 
> --
> Best Regards,
> Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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.
Visit this group at https://groups.google.com/group/bbedit.


Re: Noob trying to improve on these grep / expressions

2019-01-04 Thread Christopher Stone
On 01/04/2019, at 13:44, F. Alfredo Rego mailto:f.alfredor...@gmail.com>> wrote:
> RegExRX seems to have gone dormant five years ago. 
> 
> Do you have any news/updates regarding newer/better approaches, if any?


Hey Alfredo,

Crud.  I didn't realize it was a 32-bit app.

You can find it here:

http://www.mactechnologies.com/index.php?page=downloads#regexrx 

And you can drop the developer a note requesting an update.  (I just did.)

I usually start building a regular expression with BBEdit.

If I'm having trouble I usually go to Patterns.

But there are times when RegExRx is better, so I hope the dev gets on his 
keyboard and drums out some new code.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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.
Visit this group at https://groups.google.com/group/bbedit.


Re: Noob trying to improve on these grep / expressions

2019-01-04 Thread F. Alfredo Rego
Hey Chris,

RegExRX seems to have gone dormant five years ago. 

Do you have any news/updates regarding newer/better approaches, if any?

Thanks.

Alfredo


> On Jan 4, 2019, at 12:10 PM, Christopher Stone  
> wrote:
> 
> Tools like BBEdit , Patterns 
>  
> and/or RegExRX .

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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.
Visit this group at https://groups.google.com/group/bbedit.


Re: Replace Script w/ Date Conversion

2019-01-04 Thread Christopher Stone
On 01/04/2019, at 09:56, 'Holger Bartel' via BBEdit Talk 
mailto:bbedit@googlegroups.com>> wrote:
> I have a bunch of .yaml files in which I would like to replace/add one value 
> with a timestamp, which needs to be created from two other fields/values. I 
> think this needs the help of a filter/shell script and I’d love a pointer in 
> the direction of how to achieve this.


Hey Holger,

It would be useful to have a couple of actual example files.

You need to explain how you plan to access the files – what your actual 
workflow looks like.

It appears that you're transforming from normal date/time to epoch time - yes?

That transformation will definitely require some scripting.

You say you need to replace/add one value – what does that mean?

Are you needing to remove both the date and time stamps and replace them with 
the “Eventtimestamp”?

Or are you needing to simply add the “Eventtimestamp” after the other stamps?

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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.
Visit this group at https://groups.google.com/group/bbedit.


Replace Script w/ Date Conversion

2019-01-04 Thread 'Holger Bartel' via BBEdit Talk
Hi, 

I have a bunch of .yaml files in which I would like to replace/add one value 
with a timestamp, which needs to be created from two other fields/values. I 
think this needs the help of a filter/shell script and I’d love a pointer in 
the direction of how to achieve this.

The file looks like the below and there can be other key/value pairs in between 
or even the order could vary, but that’s more unlikely: 



Date: 2019-01-04



Time: 14:00



Eventtimestamp: 1546596000

In most files the timestamp is empty (some might not be) and needs to be 
created from the `Date` and `Time` values. 

Thanks in advance for any help and a happy new year, 
Holger

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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.
Visit this group at https://groups.google.com/group/bbedit.


Re: Noob trying to improve on these grep / expressions

2019-01-04 Thread Dj
Oh man, I was really overthinking it trying to turn it into an executable. 
Got it working and this is very cool. Appreciate you spelling it out so 
well and getting me on track! Couple more quick things: would it be hard to 
do one that only extracts text that is within quotation marks? I tried one 
off a github cheatsheet and in the past hours couldn't modify it easy, but 
am making progress. Also, if you or anyone on here can suggest a book on 
getting better at expressions and BBedit? Maybe just piecing it together 
off stackoverflow and google etc is best though? Thanks again

On Thursday, January 3, 2019 at 8:31:53 AM UTC-8, Christopher Stone wrote:
>
> On 01/01/2019, at 13:47, Dj > wrote:
>
> From what I see with your results, I think this is getting me to the place 
> of "good enough" for this problem.
>
> --
>
> Hey Dj,
>
> Very good.
>
> So the embarrasing part, I've tried to take your text and make a shell 
> script to place in the script folder. I followed directions from a tutorial 
> that had me run a command from terminal to make the text into a script: 
>
>
> I believe I gave you instructions on how to use a BBEdit Text Filter.
>
> You do *not* need to make the script executable.
>
> I then tried it in the apple script editor, plugged your text below into 
> there and then saved it as a .scpt.
>
>
> This can never work, because the Applescript Editor is for AppleScript.
>
> The Perl script is a shell script.
>
> I'm sure the daunting initial hurdles will start to make more sense.
>
>
> Yes.  Everyone who starts this journey feels lost at sea for a while.
>
> This whole text was the correct format to make a script from without Perl 
> right?
>
>
> Right.
>
> --
>
> #!/usr/bin/env perl -0777 -sw
> use v5.12;
> use utf8;
>
> my $text = <>;
> my @array = $text =~ /(\b\w[^.!]+?\?)/gms;
> $, = "\n";
> say @array;
>
> --
>
> Paste the above into a BBEdit text document.
>
> Save it in this directory:
>
> ~/Library/Application Support/BBEdit/Text Filters/
>
> (If the directory doesn't exist then create it.)
>
> Give the script a descriptive name like:
>
> MyPerlScript.pl
>
> Run it on the front document (or selection in the front document) from the:
>
> Text > Apply Text Filter > YourScriptName
>
> Menu.
>
> --
>
> AppleScript is very useful, but it's a whole different animal.
>
> Paste this into the Applescript Editor:
>
> *tell* *application* "BBEdit"
> *activate*
> *make* new *text document* with properties {*text*:"My First 
> AppleScript!"}
> *end* *tell*
>
> And click the run button or type Cmd-R.
>
> --
> Best Regards,
> Chris
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
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.
Visit this group at https://groups.google.com/group/bbedit.