Jump to content

Quick Regex Help


e1seix

Recommended Posts

Trying to find a way to use regex within an if statement. I have the following:

 

preg_match('/Mens Fragrance > ?' (.+?)?<\/div>/', $mCat, $match);
$out = $match[2];

 

it's a bit of a mess. Basically $mCat will always be "Mens Fragrance > SOMETHING" obv the SOMETHING being the variable.

 

any ideas?

Link to comment
Share on other sites

if (preg_match()) {

 

 

O_O

 

lol. it's not so much that as the whole bit of code contained within the regex. because of the ">" within the regex i'm confused and sure i don't have the ? marks and the 's in the right place...

 

many thanks,

Link to comment
Share on other sites

Trying to find a way to use regex within an if statement. I have the following:

 

preg_match('/Mens Fragrance > ?' (.+?)?<\/div>/', $mCat, $match);
$out = $match[2];

 

it's a bit of a mess. Basically $mCat will always be "Mens Fragrance > SOMETHING" obv the SOMETHING being the variable.

 

any ideas?

 

 

$mCat = 'Mens Fragrance > bla bla bla something div <div></div>';
if (preg_match('/Mens Fragrance >(?P<something>.+?)<\/div>/', $mCat, $match)) {
print_r($match);
}

http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=g2qsmaw5

 

You make us work too hard to find out what you're really asking.

What comes after 'something' is pretty important to this type of pattern, from your limited explanation that should work.

Link to comment
Share on other sites

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.