Jump to content

Regex for getting yahoo groups account


Go to solution Solved by Psycho,

Recommended Posts

hi

I have strings that contain the url of an yahoo group and it may appear in any of the following patterns:

it.groups.yahoo.com/group/batmaras/links/
it.groups.yahoo.com/group/batmaras/links
it.groups.yahoo.com/group/batmaras/
it.groups.yahoo.com/group/batmaras

 

 

I need a regex that can always capture the "batmaras" (I can't guess that part, I need to extract it using regex) and give me a result as follows:

it.groups.yahoo.com/group/batmaras

I want to remove anything after the "batmaras" part.

this is what I tried and is not working for me:

(it\.groups\.yahoo\.com\/group\/.*?)\/?

 

Link to comment
https://forums.phpfreaks.com/topic/295373-regex-for-getting-yahoo-groups-account/
Share on other sites

  • Solution
$urls = array(
    'it.groups.yahoo.com/group/batmaras/links/',
    'it.groups.yahoo.com/group/batmaras/links',
    'it.groups.yahoo.com/group/batmaras/',
    'it.groups.yahoo.com/group/batmaras'
);
 
foreach($urls as $url)
{
    echo "<br><b>INPUT:</b> {$url}<br>\n";
    if(preg_match("#it\.groups\.yahoo.com/group/([^\/]*)#is", $url, $groupMatch))
    {
        $groupName = $groupMatch[1];
        echo "<b>GROUP NAME:</b> {$groupName}<br>\n";
        $groupURL = "it.groups.yahoo.com/group/{$groupName}";
        echo "<b>GROUP URL:</b> {$groupURL}<br>\n";
    }
    else
    {
        //Did not match group name
        echo "<b>No Group Name found</b><br>\n";
    }
}

Results

INPUT: it.groups.yahoo.com/group/batmaras/links/
GROUP NAME: batmaras
GROUP URL: it.groups.yahoo.com/group/batmaras

INPUT: it.groups.yahoo.com/group/batmaras/links
GROUP NAME: batmaras
GROUP URL: it.groups.yahoo.com/group/batmaras

INPUT: it.groups.yahoo.com/group/batmaras/
GROUP NAME: batmaras
GROUP URL: it.groups.yahoo.com/group/batmaras

INPUT: it.groups.yahoo.com/group/batmaras
GROUP NAME: batmaras
GROUP URL: it.groups.yahoo.com/group/batmaras
Edited by Psycho
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.