How Can I Search for All Lines NOT Matching a Complex Regex String

31 views
Skip to first unread message

Rick Gordon

unread,
Apr 30, 2020, 6:38:50 PM4/30/20
to bbe...@googlegroups.com
I'm trying to AppleScript a solution using BBEdit (using AppleScript
because there are multi-application communications) where I could flag
the line number and content of all lines in a document not matching a
complex regex string.

For instance, if I wanted to flag all lines in document that did *NOT*
produce a match to:

^[A-Z0-9._%+-]{1,64}@(?:[A-Z0-9-]{1,63}\.){1,125}[A-Z]{2,63},[^,\r]*,[^,\r]*\r

That is, lines not structured as below:

* a line starting a possibly multi-subdomained email address
* a comma, optionally followed by some text
* a second comma, optionally followed by some more text

…how should I proceed? Is there a regex that can match those, or do I
need a more complex approach. I ultimately want to get a string of the
unmatched lines (preferably with line numbers) to throw into a dialog.

Thanks.

_______________________________________
RICK GORDON
_______________________________________

Neil Faiman

unread,
Apr 30, 2020, 7:40:06 PM4/30/20
to BBEdit Talk Mailing List
How about this?

  1. Copy the entire document to a new document.
  2. Use the add line numbers command to add line numbers to the lines in the new document.
  3. Use the process lines containing command on the new document, using your grep pattern, with the output options parameter set to { copying to clipboard: false, copying to new document: false, deleting matched lines: true, reporting results: false }.

Now your new document should contain just the lines of the original document that don't match your grep pattern, prefixed with their original line numbers

Regards,

Neil Faiman.

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" 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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/5EAB536A.2060708%40rickgordon.com.

Rick Gordon

unread,
Apr 30, 2020, 8:10:42 PM4/30/20
to bbe...@googlegroups.com
Thanks, Neil. I'd been hoping to avoid scratch documents, but that WOULD
do the job, so why not?

Thanks again,
Rick Gordon

--------------------
On April 30, 2020 at 5:08:11 PM [-0700], Neil Faiman wrote in an email
entitled "Re: How Can I Search for All Lines NOT Matching a Complex Regex
String":
>
> 1. Copy the entire document to a new document.
> 2. Use the *add line numbers* command to add line numbers to the
> lines in the new document.
> 3. Use the *process lines containing *command on the new document,
> using your grep pattern, with the *output options* parameter set
> to *{ copying to clipboard: false, copying to new document: false,
> deleting matched lines: true, reporting results: false }*.
>
> Now your new document should contain just the lines of the original
> document that don't match your grep pattern, prefixed with their
> original line numbers.
___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com
Reply all
Reply to author
Forward
0 new messages