Reputation: 41
Can someone explain what the following regexp matches?
^.*$
Thank you!
Upvotes: 3
Views: 466
Reputation: 1135
It looks like it matches everything including empty strings. The .* means that it matches everything (the period) 0 or more times (the *). The ^ and the $ are redundant if you have set the multline flag (not sure what it is in java).
Upvotes: 0
Reputation: 8020
^
= Start of string or line (depends on settings).
.
= Any character.
*
= Any number of the previous character. In this case the .
.
$
= End of string or line (depends on settings).
Put them together and it can match either a whole string or one whole line depending on what the multiline settings are (see this for more info).
Upvotes: 1
Reputation: 22830
It matches all empty and non-empty lines. It can be broken down into the following parts:
^ : match the beginning of the line
. : match any character except newline
* : match zero or many instances of the match
$ : match the ending of the line
Upvotes: 2
Reputation: 17321
It will match anything.
^
signifies the start of the line. $
signifies the end of the line. So this means that the expression must match the entire string it is passed.
.
will match any single character. *
means that the thing before it can appear between 0 to any number of times. So this means that the string can have any number of characters, including 0.
Upvotes: 1
Reputation: 12806
everything.
^ is the beginning of the string.
. is any character.
* means 0 or more of said characters.
$ is the end of the string.
So this regex matches 0 or more characters that start and end a string (which is everything).
Upvotes: 15
Reputation: 269348
Either the entire string or the entire line, depending on whether multiline mode is used.
Upvotes: 21