-5

I am receiving URL from an application as post data.

The URL has a signature : //abc.com/name?q=123456.

I want to extract name from the URL using regex ( Regular Expression ) How do I do that?

  • 2
    Short answer is don't. Use this instead: https://secure.php.net/manual/en/function.parse-url.php and get the `path` component. – Jameson Mar 30 '17 at 07:01

1 Answers1

-1

Best method is parsing url, but if you need regex to extract name :

/.+\/([^\?]+?)(\?|$)/gm

Demo

Note: this regex pattern match whole url, but captures name that you want in Group 1.

MohaMad
  • 2,575
  • 2
  • 14
  • 26