Why is regex [0-9]0,2 not greedy in sed?Non-greedy match with SED regex (emulate perl's .*?)extract part of string using sedWhy isn't sed using the extended regex mode by default?SED command not replacing (working regex)Why does regex with \${ work with egrep, but not with sed?Why does 'sed' not extend the length of a file?Explain please sed scriptSed/awk Regex : XML feedsed: regex input buffer length larger than INT_MAXWhy these two sed patterns don't give the same output?Sed not outputting matches from regex to file
How do I find the FamilyGUID of an exsting database
Do the books ever say oliphaunts aren’t elephants?
Self-deportation of American Citizens from US
Is it safe if the neutral lead is exposed and disconnected?
How did the SysRq key get onto modern keyboards if it's rarely used?
How does a poisoned arrow combine with the spell Conjure Barrage?
Why is softmax function used to calculate probabilities although we can divide each value by the sum of the vector?
How do I make my photos have more impact?
Antonym of "Megalomania"
Why is my fluorescent tube orange on one side, white on the other and dark in the middle?
What language is Raven using for her attack in the new 52?
Can Lightning Lure be used to knock out a creature like a magical Taser?
Wrapping IMemoryCache with SemaphoreSlim
If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?
How do I say "this is why…"?
In syntax, why cannot we say things like "he took walked at the park"? but can say "he took a walk at the park"?
How should I quote American English speakers in a British English essay?
Complexity of verifying optimality in (mixed) integer programming
Is it okay for me to decline a project on ethical grounds?
Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?
What is a good example for artistic ND filter applications?
Should I intervene when a colleague in a different department makes students run laps as part of their grade?
What is the reason for cards stating "Until end of turn, you don't lose this mana as steps and phases end"?
how to understand the error info "Illegal parameter number in definition of reserved@a. ...t2+cdots+sqrt2}}_n项 , cdots 收敛.$}"
Why is regex [0-9]0,2 not greedy in sed?
Non-greedy match with SED regex (emulate perl's .*?)extract part of string using sedWhy isn't sed using the extended regex mode by default?SED command not replacing (working regex)Why does regex with \${ work with egrep, but not with sed?Why does 'sed' not extend the length of a file?Explain please sed scriptSed/awk Regex : XML feedsed: regex input buffer length larger than INT_MAXWhy these two sed patterns don't give the same output?Sed not outputting matches from regex to file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
echo '123980925sriten34=ienat' | sed -e 's/^.*?([1-9][0-9]0,2+)([%=+-]).*/ 1 2 /'
is giving the result:
4 =
I am expecting:
34 =
What am I not understanding?
(Oh and I even added the +
and ?
to make doubly sure, but afaik 0,2
should be greedy without them.)
shell-script sed regular-expression
add a comment |
echo '123980925sriten34=ienat' | sed -e 's/^.*?([1-9][0-9]0,2+)([%=+-]).*/ 1 2 /'
is giving the result:
4 =
I am expecting:
34 =
What am I not understanding?
(Oh and I even added the +
and ?
to make doubly sure, but afaik 0,2
should be greedy without them.)
shell-script sed regular-expression
perl -pe 's/^.*?([1-9][0-9]0,2)([%=+-]).*/ $1 $2 /' is less annoying
– user1133275
Jul 19 at 23:59
5
Isn't it more to do with the fact that the preceding.*
is greedy?
– steeldriver
Jul 20 at 0:00
... perhaps you're thinking that the following?
makes it non-greedy?
– steeldriver
Jul 20 at 0:49
2
wrti even added the + and ? to make doubly sure
- that will probably make doubly sure the regexp won't work. You can't just throw random characters into a regexp and hope they'll somehow improve it. Also?
and+
are GNU sed only so if you aren't running GNU sed then they're going to be treated as literal chars - the POSIX equivalents are0,1
and1,
respectively.
– Ed Morton
Jul 20 at 5:08
+
and?
aren't BRE, but even if they were, stacking the repetition specifiers (*
and?
orn,m
and+
) isn't defined.
– ilkkachu
Jul 20 at 9:06
add a comment |
echo '123980925sriten34=ienat' | sed -e 's/^.*?([1-9][0-9]0,2+)([%=+-]).*/ 1 2 /'
is giving the result:
4 =
I am expecting:
34 =
What am I not understanding?
(Oh and I even added the +
and ?
to make doubly sure, but afaik 0,2
should be greedy without them.)
shell-script sed regular-expression
echo '123980925sriten34=ienat' | sed -e 's/^.*?([1-9][0-9]0,2+)([%=+-]).*/ 1 2 /'
is giving the result:
4 =
I am expecting:
34 =
What am I not understanding?
(Oh and I even added the +
and ?
to make doubly sure, but afaik 0,2
should be greedy without them.)
shell-script sed regular-expression
shell-script sed regular-expression
edited Jul 20 at 11:09
Jeff Schaller♦
48.4k11 gold badges72 silver badges161 bronze badges
48.4k11 gold badges72 silver badges161 bronze badges
asked Jul 19 at 23:52
runrinrunrin
162 bronze badges
162 bronze badges
perl -pe 's/^.*?([1-9][0-9]0,2)([%=+-]).*/ $1 $2 /' is less annoying
– user1133275
Jul 19 at 23:59
5
Isn't it more to do with the fact that the preceding.*
is greedy?
– steeldriver
Jul 20 at 0:00
... perhaps you're thinking that the following?
makes it non-greedy?
– steeldriver
Jul 20 at 0:49
2
wrti even added the + and ? to make doubly sure
- that will probably make doubly sure the regexp won't work. You can't just throw random characters into a regexp and hope they'll somehow improve it. Also?
and+
are GNU sed only so if you aren't running GNU sed then they're going to be treated as literal chars - the POSIX equivalents are0,1
and1,
respectively.
– Ed Morton
Jul 20 at 5:08
+
and?
aren't BRE, but even if they were, stacking the repetition specifiers (*
and?
orn,m
and+
) isn't defined.
– ilkkachu
Jul 20 at 9:06
add a comment |
perl -pe 's/^.*?([1-9][0-9]0,2)([%=+-]).*/ $1 $2 /' is less annoying
– user1133275
Jul 19 at 23:59
5
Isn't it more to do with the fact that the preceding.*
is greedy?
– steeldriver
Jul 20 at 0:00
... perhaps you're thinking that the following?
makes it non-greedy?
– steeldriver
Jul 20 at 0:49
2
wrti even added the + and ? to make doubly sure
- that will probably make doubly sure the regexp won't work. You can't just throw random characters into a regexp and hope they'll somehow improve it. Also?
and+
are GNU sed only so if you aren't running GNU sed then they're going to be treated as literal chars - the POSIX equivalents are0,1
and1,
respectively.
– Ed Morton
Jul 20 at 5:08
+
and?
aren't BRE, but even if they were, stacking the repetition specifiers (*
and?
orn,m
and+
) isn't defined.
– ilkkachu
Jul 20 at 9:06
perl -pe 's/^.*?([1-9][0-9]0,2)([%=+-]).*/ $1 $2 /' is less annoying
– user1133275
Jul 19 at 23:59
perl -pe 's/^.*?([1-9][0-9]0,2)([%=+-]).*/ $1 $2 /' is less annoying
– user1133275
Jul 19 at 23:59
5
5
Isn't it more to do with the fact that the preceding
.*
is greedy?– steeldriver
Jul 20 at 0:00
Isn't it more to do with the fact that the preceding
.*
is greedy?– steeldriver
Jul 20 at 0:00
... perhaps you're thinking that the following
?
makes it non-greedy?– steeldriver
Jul 20 at 0:49
... perhaps you're thinking that the following
?
makes it non-greedy?– steeldriver
Jul 20 at 0:49
2
2
wrt
i even added the + and ? to make doubly sure
- that will probably make doubly sure the regexp won't work. You can't just throw random characters into a regexp and hope they'll somehow improve it. Also ?
and +
are GNU sed only so if you aren't running GNU sed then they're going to be treated as literal chars - the POSIX equivalents are 0,1
and 1,
respectively.– Ed Morton
Jul 20 at 5:08
wrt
i even added the + and ? to make doubly sure
- that will probably make doubly sure the regexp won't work. You can't just throw random characters into a regexp and hope they'll somehow improve it. Also ?
and +
are GNU sed only so if you aren't running GNU sed then they're going to be treated as literal chars - the POSIX equivalents are 0,1
and 1,
respectively.– Ed Morton
Jul 20 at 5:08
+
and ?
aren't BRE, but even if they were, stacking the repetition specifiers (*
and ?
or n,m
and +
) isn't defined.– ilkkachu
Jul 20 at 9:06
+
and ?
aren't BRE, but even if they were, stacking the repetition specifiers (*
and ?
or n,m
and +
) isn't defined.– ilkkachu
Jul 20 at 9:06
add a comment |
1 Answer
1
active
oldest
votes
The problem, as steeldriver states,
isn’t that the [0-9]0,2
is non-greedy;
the problem is that the .*?
before it is greedy. sed
supports BRE and ERE, neither of which supports non-greedy matching.
That’s a feature of PCREs.
For example, the following commands:
$ echo 'aQbQc' | sed 's/.*?Q/X/'
$ echo 'aQbQc' | sed 's/.*Q/X/'
$ echo 'aQbQc' | sed -r 's/.*?Q/X/'
$ echo 'aQbQc' | sed -r 's/.*Q/X/'
all output
Xc
(I’m not sure why it just ignores the ?
.)
See Non-greedy match with SED regex (emulate perl's .*?
).
Your description of the function that you want to perform is skimpy,
but I believe that I’ve reverse engineered it.
You can get the desired effect by not matching the characters
before the number you want to match until after you’ve found the number:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/! 1 2 /' -e 's/.*!//'
34 =
replacing the !
with any string known not to appear in the input data.
If you have no such string, but you’re using GNU sed, you can use newline:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/n 1 2 /' -e 's/.*n//'
34 =
which, of course, cannot appear in any line.
5
wrtI’m not sure why it just ignores the ?
- because?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it meanszero-or-1
just ignoring it is as reasonable approach as any. Essentially.*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).
– Ed Morton
Jul 20 at 5:01
5
On a GNU system, the repetition operators stack,?
after+
(using ERE syntax) makes the whole thing optional (same as*
), and2,4?
matches 0, 2, 3 or 4 repetitions (trygrep -Eoe 'ba2,4?b'
againstbb
,bab
,baab
).*?
is just the same as*
since*
can already match zero repetitions. The thing where?
makes a pattern non-greedy is a feature of Perl regexes.
– ilkkachu
Jul 20 at 9:03
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f531098%2fwhy-is-regex-0-90-2-not-greedy-in-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem, as steeldriver states,
isn’t that the [0-9]0,2
is non-greedy;
the problem is that the .*?
before it is greedy. sed
supports BRE and ERE, neither of which supports non-greedy matching.
That’s a feature of PCREs.
For example, the following commands:
$ echo 'aQbQc' | sed 's/.*?Q/X/'
$ echo 'aQbQc' | sed 's/.*Q/X/'
$ echo 'aQbQc' | sed -r 's/.*?Q/X/'
$ echo 'aQbQc' | sed -r 's/.*Q/X/'
all output
Xc
(I’m not sure why it just ignores the ?
.)
See Non-greedy match with SED regex (emulate perl's .*?
).
Your description of the function that you want to perform is skimpy,
but I believe that I’ve reverse engineered it.
You can get the desired effect by not matching the characters
before the number you want to match until after you’ve found the number:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/! 1 2 /' -e 's/.*!//'
34 =
replacing the !
with any string known not to appear in the input data.
If you have no such string, but you’re using GNU sed, you can use newline:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/n 1 2 /' -e 's/.*n//'
34 =
which, of course, cannot appear in any line.
5
wrtI’m not sure why it just ignores the ?
- because?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it meanszero-or-1
just ignoring it is as reasonable approach as any. Essentially.*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).
– Ed Morton
Jul 20 at 5:01
5
On a GNU system, the repetition operators stack,?
after+
(using ERE syntax) makes the whole thing optional (same as*
), and2,4?
matches 0, 2, 3 or 4 repetitions (trygrep -Eoe 'ba2,4?b'
againstbb
,bab
,baab
).*?
is just the same as*
since*
can already match zero repetitions. The thing where?
makes a pattern non-greedy is a feature of Perl regexes.
– ilkkachu
Jul 20 at 9:03
add a comment |
The problem, as steeldriver states,
isn’t that the [0-9]0,2
is non-greedy;
the problem is that the .*?
before it is greedy. sed
supports BRE and ERE, neither of which supports non-greedy matching.
That’s a feature of PCREs.
For example, the following commands:
$ echo 'aQbQc' | sed 's/.*?Q/X/'
$ echo 'aQbQc' | sed 's/.*Q/X/'
$ echo 'aQbQc' | sed -r 's/.*?Q/X/'
$ echo 'aQbQc' | sed -r 's/.*Q/X/'
all output
Xc
(I’m not sure why it just ignores the ?
.)
See Non-greedy match with SED regex (emulate perl's .*?
).
Your description of the function that you want to perform is skimpy,
but I believe that I’ve reverse engineered it.
You can get the desired effect by not matching the characters
before the number you want to match until after you’ve found the number:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/! 1 2 /' -e 's/.*!//'
34 =
replacing the !
with any string known not to appear in the input data.
If you have no such string, but you’re using GNU sed, you can use newline:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/n 1 2 /' -e 's/.*n//'
34 =
which, of course, cannot appear in any line.
5
wrtI’m not sure why it just ignores the ?
- because?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it meanszero-or-1
just ignoring it is as reasonable approach as any. Essentially.*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).
– Ed Morton
Jul 20 at 5:01
5
On a GNU system, the repetition operators stack,?
after+
(using ERE syntax) makes the whole thing optional (same as*
), and2,4?
matches 0, 2, 3 or 4 repetitions (trygrep -Eoe 'ba2,4?b'
againstbb
,bab
,baab
).*?
is just the same as*
since*
can already match zero repetitions. The thing where?
makes a pattern non-greedy is a feature of Perl regexes.
– ilkkachu
Jul 20 at 9:03
add a comment |
The problem, as steeldriver states,
isn’t that the [0-9]0,2
is non-greedy;
the problem is that the .*?
before it is greedy. sed
supports BRE and ERE, neither of which supports non-greedy matching.
That’s a feature of PCREs.
For example, the following commands:
$ echo 'aQbQc' | sed 's/.*?Q/X/'
$ echo 'aQbQc' | sed 's/.*Q/X/'
$ echo 'aQbQc' | sed -r 's/.*?Q/X/'
$ echo 'aQbQc' | sed -r 's/.*Q/X/'
all output
Xc
(I’m not sure why it just ignores the ?
.)
See Non-greedy match with SED regex (emulate perl's .*?
).
Your description of the function that you want to perform is skimpy,
but I believe that I’ve reverse engineered it.
You can get the desired effect by not matching the characters
before the number you want to match until after you’ve found the number:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/! 1 2 /' -e 's/.*!//'
34 =
replacing the !
with any string known not to appear in the input data.
If you have no such string, but you’re using GNU sed, you can use newline:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/n 1 2 /' -e 's/.*n//'
34 =
which, of course, cannot appear in any line.
The problem, as steeldriver states,
isn’t that the [0-9]0,2
is non-greedy;
the problem is that the .*?
before it is greedy. sed
supports BRE and ERE, neither of which supports non-greedy matching.
That’s a feature of PCREs.
For example, the following commands:
$ echo 'aQbQc' | sed 's/.*?Q/X/'
$ echo 'aQbQc' | sed 's/.*Q/X/'
$ echo 'aQbQc' | sed -r 's/.*?Q/X/'
$ echo 'aQbQc' | sed -r 's/.*Q/X/'
all output
Xc
(I’m not sure why it just ignores the ?
.)
See Non-greedy match with SED regex (emulate perl's .*?
).
Your description of the function that you want to perform is skimpy,
but I believe that I’ve reverse engineered it.
You can get the desired effect by not matching the characters
before the number you want to match until after you’ve found the number:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/! 1 2 /' -e 's/.*!//'
34 =
replacing the !
with any string known not to appear in the input data.
If you have no such string, but you’re using GNU sed, you can use newline:
$ echo '123980925sriten34=ienat' | sed -e 's/([1-9][0-9]0,2+)([%=+-]).*/n 1 2 /' -e 's/.*n//'
34 =
which, of course, cannot appear in any line.
answered Jul 20 at 1:37
G-ManG-Man
15.2k9 gold badges43 silver badges81 bronze badges
15.2k9 gold badges43 silver badges81 bronze badges
5
wrtI’m not sure why it just ignores the ?
- because?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it meanszero-or-1
just ignoring it is as reasonable approach as any. Essentially.*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).
– Ed Morton
Jul 20 at 5:01
5
On a GNU system, the repetition operators stack,?
after+
(using ERE syntax) makes the whole thing optional (same as*
), and2,4?
matches 0, 2, 3 or 4 repetitions (trygrep -Eoe 'ba2,4?b'
againstbb
,bab
,baab
).*?
is just the same as*
since*
can already match zero repetitions. The thing where?
makes a pattern non-greedy is a feature of Perl regexes.
– ilkkachu
Jul 20 at 9:03
add a comment |
5
wrtI’m not sure why it just ignores the ?
- because?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it meanszero-or-1
just ignoring it is as reasonable approach as any. Essentially.*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).
– Ed Morton
Jul 20 at 5:01
5
On a GNU system, the repetition operators stack,?
after+
(using ERE syntax) makes the whole thing optional (same as*
), and2,4?
matches 0, 2, 3 or 4 repetitions (trygrep -Eoe 'ba2,4?b'
againstbb
,bab
,baab
).*?
is just the same as*
since*
can already match zero repetitions. The thing where?
makes a pattern non-greedy is a feature of Perl regexes.
– ilkkachu
Jul 20 at 9:03
5
5
wrt
I’m not sure why it just ignores the ?
- because ?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it means zero-or-1
just ignoring it is as reasonable approach as any. Essentially .*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).– Ed Morton
Jul 20 at 5:01
wrt
I’m not sure why it just ignores the ?
- because ?
after another repetition RE metachar (*
in this case) is undefined behavior per POSIX and since in other contexts it means zero-or-1
just ignoring it is as reasonable approach as any. Essentially .*?
should be treated as bug in a regexp as it doesn't have any sensible meaning (zero-or one repetitions of zero-or-more repetitions of any character - huh?).– Ed Morton
Jul 20 at 5:01
5
5
On a GNU system, the repetition operators stack,
?
after +
(using ERE syntax) makes the whole thing optional (same as *
), and 2,4?
matches 0, 2, 3 or 4 repetitions (try grep -Eoe 'ba2,4?b'
against bb
, bab
, baab
). *?
is just the same as *
since *
can already match zero repetitions. The thing where ?
makes a pattern non-greedy is a feature of Perl regexes.– ilkkachu
Jul 20 at 9:03
On a GNU system, the repetition operators stack,
?
after +
(using ERE syntax) makes the whole thing optional (same as *
), and 2,4?
matches 0, 2, 3 or 4 repetitions (try grep -Eoe 'ba2,4?b'
against bb
, bab
, baab
). *?
is just the same as *
since *
can already match zero repetitions. The thing where ?
makes a pattern non-greedy is a feature of Perl regexes.– ilkkachu
Jul 20 at 9:03
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f531098%2fwhy-is-regex-0-90-2-not-greedy-in-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
perl -pe 's/^.*?([1-9][0-9]0,2)([%=+-]).*/ $1 $2 /' is less annoying
– user1133275
Jul 19 at 23:59
5
Isn't it more to do with the fact that the preceding
.*
is greedy?– steeldriver
Jul 20 at 0:00
... perhaps you're thinking that the following
?
makes it non-greedy?– steeldriver
Jul 20 at 0:49
2
wrt
i even added the + and ? to make doubly sure
- that will probably make doubly sure the regexp won't work. You can't just throw random characters into a regexp and hope they'll somehow improve it. Also?
and+
are GNU sed only so if you aren't running GNU sed then they're going to be treated as literal chars - the POSIX equivalents are0,1
and1,
respectively.– Ed Morton
Jul 20 at 5:08
+
and?
aren't BRE, but even if they were, stacking the repetition specifiers (*
and?
orn,m
and+
) isn't defined.– ilkkachu
Jul 20 at 9:06