-2

I found these two expressions in documentation:

To match subdomains of mydomain.com: (^|.*\.)mydomain\.com

To match domain and subdomains of mydomain.com: (^|.*\.)*mydomain\.com

I can't understand why those expressions mean what they say they mean. Can anybody explain both expressions please?

1 Answers1

0

Fist it is not a good regex expressions (it except other things that it should not) but i will explain the (^|.*\.)mydomain\.com (you will figure out the second)

  • between the parenthesis :

^ matches the starting position of the line

| acts like a Boolean OR ,between the expression before and the expression after the operator

.matches any character except line breaks

*Matches the preceding element zero or more times

\.matches a dot . character

For more information you could read wiki doc and use a great Regex tool

Tarek Baz
  • 393
  • 4
  • 18