What are some PRACTICAL scenarios for using the regex + symbol?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...
echo "This is a good sentence." | awk '/go+d/ print $0'
(finds good, gooood, gooooooood)
But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.
Thanks for helping and letting me lean on your knowledge and experiences.
regular-expression
add a comment |Â
up vote
0
down vote
favorite
So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...
echo "This is a good sentence." | awk '/go+d/ print $0'
(finds good, gooood, gooooooood)
But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.
Thanks for helping and letting me lean on your knowledge and experiences.
regular-expression
It makes more sense with digits, as I see it...
â jasonwryan
Oct 10 '17 at 2:14
I thought that too, but I couldn't think of a scenario to explain how that would look.
â dlowrie290
Oct 10 '17 at 2:22
1
What about when you want to slurp up whitespace? At least one space, for example.s+
. Think about character classes rather than individual characters.
â B Layer
Oct 10 '17 at 2:28
That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
â dlowrie290
Oct 10 '17 at 2:33
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...
echo "This is a good sentence." | awk '/go+d/ print $0'
(finds good, gooood, gooooooood)
But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.
Thanks for helping and letting me lean on your knowledge and experiences.
regular-expression
So, I think I know what the RegEx + symbol does (looks for the preceding character 1 or more times). I think I get how to use it...
echo "This is a good sentence." | awk '/go+d/ print $0'
(finds good, gooood, gooooooood)
But, I'm having trouble coming up with a practical, objective reason for wanting to look for this kind of repetition. I need scenarios to give its purpose some context for explanation to others.
Thanks for helping and letting me lean on your knowledge and experiences.
regular-expression
regular-expression
asked Oct 10 '17 at 2:09
dlowrie290
8410
8410
It makes more sense with digits, as I see it...
â jasonwryan
Oct 10 '17 at 2:14
I thought that too, but I couldn't think of a scenario to explain how that would look.
â dlowrie290
Oct 10 '17 at 2:22
1
What about when you want to slurp up whitespace? At least one space, for example.s+
. Think about character classes rather than individual characters.
â B Layer
Oct 10 '17 at 2:28
That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
â dlowrie290
Oct 10 '17 at 2:33
add a comment |Â
It makes more sense with digits, as I see it...
â jasonwryan
Oct 10 '17 at 2:14
I thought that too, but I couldn't think of a scenario to explain how that would look.
â dlowrie290
Oct 10 '17 at 2:22
1
What about when you want to slurp up whitespace? At least one space, for example.s+
. Think about character classes rather than individual characters.
â B Layer
Oct 10 '17 at 2:28
That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
â dlowrie290
Oct 10 '17 at 2:33
It makes more sense with digits, as I see it...
â jasonwryan
Oct 10 '17 at 2:14
It makes more sense with digits, as I see it...
â jasonwryan
Oct 10 '17 at 2:14
I thought that too, but I couldn't think of a scenario to explain how that would look.
â dlowrie290
Oct 10 '17 at 2:22
I thought that too, but I couldn't think of a scenario to explain how that would look.
â dlowrie290
Oct 10 '17 at 2:22
1
1
What about when you want to slurp up whitespace? At least one space, for example.
s+
. Think about character classes rather than individual characters.â B Layer
Oct 10 '17 at 2:28
What about when you want to slurp up whitespace? At least one space, for example.
s+
. Think about character classes rather than individual characters.â B Layer
Oct 10 '17 at 2:28
That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
â dlowrie290
Oct 10 '17 at 2:33
That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
â dlowrie290
Oct 10 '17 at 2:33
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
You're thinking about individual characters when you'll find that +
is much more useful with character classes...
- Whitespace:
s+
- Non-numerical characters:
[^0-9]+
- A word:
w+
- Non-empty string:
.+
- Etc.
Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S
. Or I might want to find all non-empty lines: ^.+$
. I can come up with more if you need them. ;)
No,[0-9]
is numerical.[^0-9]
is NOT numerical.
â B Layer
Oct 10 '17 at 2:44
My bad, I read it as^[
...
â jasonwryan
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
add a comment |Â
up vote
3
down vote
Here's a real-world instance of damage caused by using *
instead of +
(mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?
Arguments to
apt-get install
andapt-get remove
are extended
regular expressions, not shell
wildcards;
wine*
meanswin
followed by any number ofe
, and since this can
match any part of the package name, this means any package whose name
containswin
as a substring.
OP had run sudo apt-get remove wine*
, ended up removing the majority of the installed packages in their system. wine+
, on the other hand, would have removed packages with wine
in it.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
You're thinking about individual characters when you'll find that +
is much more useful with character classes...
- Whitespace:
s+
- Non-numerical characters:
[^0-9]+
- A word:
w+
- Non-empty string:
.+
- Etc.
Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S
. Or I might want to find all non-empty lines: ^.+$
. I can come up with more if you need them. ;)
No,[0-9]
is numerical.[^0-9]
is NOT numerical.
â B Layer
Oct 10 '17 at 2:44
My bad, I read it as^[
...
â jasonwryan
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
add a comment |Â
up vote
4
down vote
accepted
You're thinking about individual characters when you'll find that +
is much more useful with character classes...
- Whitespace:
s+
- Non-numerical characters:
[^0-9]+
- A word:
w+
- Non-empty string:
.+
- Etc.
Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S
. Or I might want to find all non-empty lines: ^.+$
. I can come up with more if you need them. ;)
No,[0-9]
is numerical.[^0-9]
is NOT numerical.
â B Layer
Oct 10 '17 at 2:44
My bad, I read it as^[
...
â jasonwryan
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
You're thinking about individual characters when you'll find that +
is much more useful with character classes...
- Whitespace:
s+
- Non-numerical characters:
[^0-9]+
- A word:
w+
- Non-empty string:
.+
- Etc.
Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S
. Or I might want to find all non-empty lines: ^.+$
. I can come up with more if you need them. ;)
You're thinking about individual characters when you'll find that +
is much more useful with character classes...
- Whitespace:
s+
- Non-numerical characters:
[^0-9]+
- A word:
w+
- Non-empty string:
.+
- Etc.
Practical examples should be fairly easy to think of with these. Perhaps I want to find only lines that have indented text: ^s+S
. Or I might want to find all non-empty lines: ^.+$
. I can come up with more if you need them. ;)
edited Oct 10 '17 at 3:29
answered Oct 10 '17 at 2:42
B Layer
3,9241525
3,9241525
No,[0-9]
is numerical.[^0-9]
is NOT numerical.
â B Layer
Oct 10 '17 at 2:44
My bad, I read it as^[
...
â jasonwryan
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
add a comment |Â
No,[0-9]
is numerical.[^0-9]
is NOT numerical.
â B Layer
Oct 10 '17 at 2:44
My bad, I read it as^[
...
â jasonwryan
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
No,
[0-9]
is numerical. [^0-9]
is NOT numerical.â B Layer
Oct 10 '17 at 2:44
No,
[0-9]
is numerical. [^0-9]
is NOT numerical.â B Layer
Oct 10 '17 at 2:44
My bad, I read it as
^[
...â jasonwryan
Oct 10 '17 at 2:45
My bad, I read it as
^[
...â jasonwryan
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
No worries. I suspected that that's what you saw. :)
â B Layer
Oct 10 '17 at 2:45
add a comment |Â
up vote
3
down vote
Here's a real-world instance of damage caused by using *
instead of +
(mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?
Arguments to
apt-get install
andapt-get remove
are extended
regular expressions, not shell
wildcards;
wine*
meanswin
followed by any number ofe
, and since this can
match any part of the package name, this means any package whose name
containswin
as a substring.
OP had run sudo apt-get remove wine*
, ended up removing the majority of the installed packages in their system. wine+
, on the other hand, would have removed packages with wine
in it.
add a comment |Â
up vote
3
down vote
Here's a real-world instance of damage caused by using *
instead of +
(mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?
Arguments to
apt-get install
andapt-get remove
are extended
regular expressions, not shell
wildcards;
wine*
meanswin
followed by any number ofe
, and since this can
match any part of the package name, this means any package whose name
containswin
as a substring.
OP had run sudo apt-get remove wine*
, ended up removing the majority of the installed packages in their system. wine+
, on the other hand, would have removed packages with wine
in it.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Here's a real-world instance of damage caused by using *
instead of +
(mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?
Arguments to
apt-get install
andapt-get remove
are extended
regular expressions, not shell
wildcards;
wine*
meanswin
followed by any number ofe
, and since this can
match any part of the package name, this means any package whose name
containswin
as a substring.
OP had run sudo apt-get remove wine*
, ended up removing the majority of the installed packages in their system. wine+
, on the other hand, would have removed packages with wine
in it.
Here's a real-world instance of damage caused by using *
instead of +
(mostly because OP didn't realise that they would end up using regexes instead of wildcards): Why did this command delete every package?
Arguments to
apt-get install
andapt-get remove
are extended
regular expressions, not shell
wildcards;
wine*
meanswin
followed by any number ofe
, and since this can
match any part of the package name, this means any package whose name
containswin
as a substring.
OP had run sudo apt-get remove wine*
, ended up removing the majority of the installed packages in their system. wine+
, on the other hand, would have removed packages with wine
in it.
answered Oct 10 '17 at 2:44
muru
33.6k577144
33.6k577144
add a comment |Â
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%2f397155%2fwhat-are-some-practical-scenarios-for-using-the-regex-symbol%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
It makes more sense with digits, as I see it...
â jasonwryan
Oct 10 '17 at 2:14
I thought that too, but I couldn't think of a scenario to explain how that would look.
â dlowrie290
Oct 10 '17 at 2:22
1
What about when you want to slurp up whitespace? At least one space, for example.
s+
. Think about character classes rather than individual characters.â B Layer
Oct 10 '17 at 2:28
That is EXACTLY the kind of thing I'm looking for. A great example of why you would use this type of functionality.
â dlowrie290
Oct 10 '17 at 2:33