Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: grep question using multiple lines

by eye (Chaplain)
on Dec 28, 2008 at 03:05 UTC ( #732862=note: print w/replies, xml ) Need Help??

in reply to grep question using multiple lines

This seems to work, though it assumes that there is no more than one address per line:
replaced by "\1". You can use "Replace All" and get the result you want. If you are willing to accept a multi-step solution, you can make this more robust and easily eliminate the assumption of no more than one address per line.

In my usage, I'd be inclined to use a regex in "Process Lines Containing..." to eliminate lines without an email address. I'd then extract the email addresses from the remaining lines with a regex. I believe all of this could be automated in a BBEdit Text Factory.

Replies are listed 'Best First'.
Re^2: grep question using multiple lines
by backstab (Novice) on Dec 28, 2008 at 03:31 UTC

    My solution with the while loop works with many emails on the same line. In fact doing so we consider the text as a whole totally ignoring newlines.

    The idea of /g flag within a while is each match will start where the previous one has stopped and the loop stops when there is no more successful match.

    The special variable @- is an array with the match start and end positions respectivly as $-[0] and $-[1] it might help to see what the loop does,

    while ($txt =~ /constant=(\w+@\w+\.\w+)/g) { print "==> match starts at $-[0]!!!\n"; print "$1\n"; }
      bradcathey (the OP) wrote:
      I'm trying to isolate some code in BBEdit using the grep functionality offered (Perl friendly).
      By my reading, the OP wants to know how to use the PCRE capability of BBEdit (or TextWrangler) to accomplish this task. While BBEdit has a mechanism for invoking scripts, I do not think that was what the OP was asking about. There are many merits to your answer, but it is not something that can be implemented directly in BBEdit.
Re^2: grep question using multiple lines
by bradcathey (Prior) on Dec 28, 2008 at 13:58 UTC

    This is what I was looking for, basically. Your original script still failed to clear the inbetween lines, but when I added one more \r before the alternation operator it worked to prefection:



    Perfecto! Thanks eye.

    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://732862]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2017-09-24 06:23 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (273 votes). Check out past polls.