Putting a `?` after a quantifier like `*` or `+` indicates that you want it to be _lazy_ instead of _greedy_. In short, this means that the quantifier will match the shortest string possible rather than the longest string possible.

For example, take the text `aaabaaba`. The pattern `.*b` will match `aaabaab`, while the pattern `.*?b` will match `aaab`.

In your pattern the `?` is unnecessary because the pattern is anchored to the end of the line with `$`. That makes the shortest and longest possible matches for `.+` the same. But it doesn’t hurt either. I tend to make my quantifiers lazy with `?` unless I have a reason not to.

Your pattern can be read as “match a literal backslash, followed by one or more of any character (lazily), followed by the end of the line”.

Hope this helps.
-sam

On 19 Dec 2019, at 11:58, Howard wrote:

I am new both to BBEdit and to GREP and have a question about this GREP
code:

\\.+?$

It is used in Search's Find box to remove all text from the backslash on,
and is accompanied by no value in the Replace box.

*Sample Input*
Tyler Rogers\rogerty01

*Desired Output*
Tyler Rogers

I understand that the two backslashes seek the backslashes in my text, that
the "." seeks "any character except a ‘hard’ line break" after the
backslash, and that the "$" continues the search to the line's end. But
what does the question mark do?

Howard

--
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: <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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/c59021ba-c7aa-4790-af66-dfd5fba423fa%40googlegroups.com.


--
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: <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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/AEC2DF1B-C985-4A95-907F-1EA37C840478%40munkynet.org.

Reply via email to