Remove any content starting from a and ending at b
-
I am trying to regex search like this
(http).*(",)
, but instead of matching multiple areas that are between anhttp
string and a",
string, it instead selects the ENTIRE area from the first ever occurence ofhttp
up until the last occurence of",
which is NOT what I want, I instead want it to find all the instances of areas between those two strings.Any help for this will be gladly appreciated!^^
-
The sub-expression
.*
will try to capture as much as possible, which is why your expression is grabbing from the first http to the last",
. To make it non-greedy, in order to capture the least amount possible (and thus the firsthttp
to the first",
), use.*?
– the?
modifies the*
to be non-greedy. -
the ENTIRE area from the first ever occurence of http up until the last occurence of ",
Sounds like it’s matching multiple lines. To stop this, ensure that in Find window, Search mode, “. matches newline” is not checked. This will confine matches to (parts of) each line.
Then, either your orig (greedy) or non-greedy as per Peter’s suggestion, will give the hoped for result.
-
@Neil-Schipper said in Remove any content starting from a and ending at b:
ensure that in Find window, Search mode, “. matches newline” is not checked. This will confine matches to (parts of) each line.
Careful with a statement such as that, as I can easily write a regular expression that will have multiple lines in a single match even when that checkbox is checked.
It only disallows the
.
used in the regex to match line-ending characters; it does nothing to prevent other constructs from matching across line boundaries. -
@Alan-Kilborn Of course, but we are discussing the actual search string @Auditormadness9 tried, which won’t span lines with the “dot matches” deselected as I suggested.
-
Correct, but other people come along and read this stuff and perhaps would grab onto a statement like “. matches newline…will confine matches to parts of each line”.
-
And anyway, for all we know, the OP does want to span lines with his matches. Who’s to say, because he (OP) didn’t.
-
for all we know, the OP does want to span lines with his matches
OP wrote:
but instead of matching multiple areas that are between an http string and a "
which sounds to me like he wants the greedy form but acting per line.
-
It’s inconclusive, unless OP comes back for more help.
We’ve seen it many times.