On 29-Sep-2008, at 14:26, Ewelk wrote:
> What does the ? represent?
In grep the ? has a variety of uses. In this case it means "match
greedy left instead of greedy right". In other cases it means "the
preceding pattern is optional. For example
^.?$
Will match a line that has 0 or one characters on it.
cars? will match "car" or "cars"
In still other cases, the ? can be used to store a pattern in a named
variable, or to do look-ahead or look-behind searches. That's a topic
for another day (and for someone with a clue, I don't grok look-ahead/-
behind).
On to the posted search pattern
(^.+?)
Means "starting at the beginning of the line (^) match any character
(.) one or more times (+) and match 'greedy left' (?). the () mean to
capture the match. I always put ^ or $ outside of parentheses myself.
Greedy left is really "match as little as possible".
This '(\()' matches a left parentheses and captures it (I think this
is useless in this case).
(\) ) matches a right parentheses and a space and captures it, again,
uselessly.
You could do (^.+?)(\()(.+?)(\) )(.+) instead like this:
^([^\(]+)\(([^\)]+)\) (.+)
(From start of line capture all the non ( characters, then a ( then
all the non ) characters, then ) followed by a space, then one or more
of any character. As far as I can see, these are effectively the
same, but my brain understands the latter one a lot easier than the
former.)
> Centralized Documents (331 20th Street) Files including A-Z
To
> Centralized Documents
> 331 20th Street ADDRESS
>
> Files including A-Z
Search:
^([^\(]+)\(([^\)]+)\) (.+)
Replace
\1\r\2 ADDRESS\r\r\3
Tested and confirmed to work. If you're having trouble, you've not
given us all the details or the sample data does not match the real
data.
--
"Katrina, $4 gas, a trillion dollar war, rising unemployment,
deregulated housing market, global warming...NO MORE!"
http://is.gd/2mxY
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or
confirmed) problem with the software, please email to "[EMAIL PROTECTED]"
rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---