Need help with PHP Regular expression?

Could you please provide me with a Regular expression to convert to value word that comes after tags/word_to_convert_to_value that can be used in other functions.

I am creating plugin that will grab then URL the grab the word that comes after tags/word_to_convert_to_value and then use that word to do search for similar words in the database.

Please need expression?

The string ends after “value”?


the captured subpattern is what you’re after.

I am terrible with PHP so please help me here. This is what I want.

$actual_link = "$_SERVER[REQUEST_URI]";
$tomatch = "/tags/";
if ($actual_link == $tomatch)
//convert whatever comes after /tags/ to value?

In StarLion’s example whatever follows tags/ up to the next non alphanumeric character is captured.

With numlock’s example everything after tags/ to the end of the file is captured.

Thanks very much but how to incorporate this:


Into my code?

$actual_link = $_SERVER['REQUEST_URI'];
preg_match('~tags/(\w+)$~', $actual_link, $matches);
$value = $matches[1];

and now $value contains the value you are after.


Awesome. Thanks very much. Works great. +1 from me :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.