New to regex, trouble with some code

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
luwin
Forum Newbie
Posts: 1
Joined: Mon May 18, 2009 8:22 am

New to regex, trouble with some code

Post by luwin »

EDIT: Ok, actually fixed my first problem.

Problem two though:

Is it possible to have a conditional to a preg_match_all? Lets say I want some text if something, if not, then I get something else. For example:

My trouble is that I have a site that is something like this:

Product: Product name
Production year: year
website: link

The website has a list of these. Trouble is that some products does not have a website (and therefore not a link). What happens when I do a preg_match_all in my code is that if product 3 does not have a website, but product 4 does, then product 3 is associated with product 4's site. And then product 4 is not associated with any site. How can I solve this problem?

I really appreciate any help!
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: New to regex, trouble with some code

Post by GeertDD »

It is possible to include an empty match for products without a website. If you want a real regex, I suggest you supply us with an example source string of product data.
Post Reply