Validate Google Site Verification URL with Regex

Asked

Viewed 154 times

2

With $_SERVER['REQUEST_URI'] I capture the following address below!

/google9f7804416f93fdd6b.html

I need to perform a validation with ER, the function has to recognize the word Google the parâmetros randômicos 9f7804416f93fdd6b and the extension .html, so that we can call the controller manually GoogleController.

I have tried here with some examples, but always false.

  • You can put the full url?

  • @rray the full url would be http://www.site.com.br/google9f7804416f93fdd6b.html

1 answer

4


Good, I think this regex works for what you want:

[Gg]oogle[a-z0-9]*.html

will detect google or google, any character for Random values and then html extension. If you want me to detect other extensions you can do:

[Gg]oogle[a-z0-9]*.[a-z]

To get the values of what regex picked up, just put () around what you want to get. For example to get the values:

[Gg]oogle([a-z0-9]*).[a-z]
  • 3

    Just commenting, @Rui no [G,g] the comma does not separate the characters, this is not necessary can be put only [Gg], the way it is, you’re capturing G, g, ",".

  • @Guilhermelautert is right, I’m sorry for the mistake. It’s already fixed

  • No problems = D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.