problem understaning /.*/

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.
but this is not the thing it does. why?
my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?
regular-expression ed
add a comment |Â
up vote
0
down vote
favorite
I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.
but this is not the thing it does. why?
my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?
regular-expression ed
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.
but this is not the thing it does. why?
my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?
regular-expression ed
I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding character. so I expect that /.*/ finds something like rrr qqqq abbbbb, I mean continuouslynuesly repetition of a single character.
but this is not the thing it does. why?
my second question is: why /.+/ doesn't do the same thing?? in the text I'm trying on the result is ?
regular-expression ed
asked yesterday
Fatemeh Karimi
1154
1154
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..
This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.
If you'd like to find a line that contains a repeated character, use
/(.)11*/
This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in
/^(.)11*$/
The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.
The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".
According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.
1
Even if the*referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
â ilkkachu
yesterday
1
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..
This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.
If you'd like to find a line that contains a repeated character, use
/(.)11*/
This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in
/^(.)11*$/
The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.
The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".
According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.
1
Even if the*referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
â ilkkachu
yesterday
1
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
add a comment |Â
up vote
3
down vote
accepted
No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..
This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.
If you'd like to find a line that contains a repeated character, use
/(.)11*/
This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in
/^(.)11*$/
The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.
The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".
According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.
1
Even if the*referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
â ilkkachu
yesterday
1
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..
This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.
If you'd like to find a line that contains a repeated character, use
/(.)11*/
This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in
/^(.)11*$/
The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.
The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".
According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.
No, the * in .* means "any number of the preceding expression", i.e. zero or more of whatever character that matches the expression ..
This means that .* will match aaaa as well as abcd since all of the characters in abcd matches .. It will also match an empty line, since it allows for zero matches.
If you'd like to find a line that contains a repeated character, use
/(.)11*/
This expression matches "any character, then the same character, and then any number of more of the same character". The 1* could arguably be removed unless you're looking for lines that contain only a repeated character, in which case you should anchor the expression to the start and end of the line, as in
/^(.)11*$/
The ed editor supports basic regular expressions. The + modifier is an extended regular expression modifier. The ? that you get from ed when using /.+/ would be followed by no match (or No match in GNU ed) if you had enabled error explanations with the H command. This is because it tries to find a line with a + in it, preceded by some other character.
The .+ extended regular expression ("match one or more of any character") is equivalent to the basic regular expression ..*, i.e. "match a character, and then zero or more of any character".
According to its manual, GNU ed should support + in regular expressions, so that ..* is equivalent to .+, but GNU ed 1.14.2 on my OpenBSD system does not do this.
edited yesterday
answered yesterday
Kusalananda
100k13199311
100k13199311
1
Even if the*referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
â ilkkachu
yesterday
1
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
add a comment |Â
1
Even if the*referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...
â ilkkachu
yesterday
1
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
1
1
Even if the
* referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...â ilkkachu
yesterday
Even if the
* referred to copies of the same character, it matches zero or more, so it would still match on any line since a zero amount of something is really easy to find...â ilkkachu
yesterday
1
1
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
Great work and congrats on the 100K!
â Stephen Rauch
yesterday
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460619%2fproblem-understaning%23new-answer', 'question_page');
);
Post as a guest
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
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
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