Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:35:28+00:00 2026-06-03T02:35:28+00:00

I am having a bit of a problem with some regex I did for

  • 0

I am having a bit of a problem with some regex I did for a project of mine (please keep in mind that I am a beginner at regex which shows in the follwoing example). I am having a bit of a problem with a piece of xml code from which I am trying to extract certain parts of it using an associated pattern.

<banner piclink="pic" urlactive="url_active" urltarget="globaltgt" urllink="globallink" timevar="globaldelay" swf="0" smooth="1" name="name" alt="alternate" />

I am using the following regular expression to obtain the piclink, urlactive, urltarget, urllink and timevar using preg_match_all:

/piclink=\"(?<pic>.+)\".+urltarget=\"(?<target>.+)\".+urllink=\"(?<url>.*)\".+timevar=\"(?<delay>.*)\"/iU

So far so good everything works right however, I am now trying to capture with association the name and alt tags which are optional as in they don’t always appear. I have tried to put them in parenthesis followed by a ? to indicate that they are optional like such:

(name=\"(?<name>.*)\")?

However the $matches[‘name’] array is always empty, I do not know where I am messing up but I have tried all sorts of combinations and all of them result in an empty result except for when I put (?: at the end and encapsulate everything from swf= onwards then it does return like 115 results in the array which is not acceptabe as the result is like $matches[‘name’][X] = result, where x is sometimes 1 other times its at 109 for some reason.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:35:30+00:00Added an answer on June 3, 2026 at 2:35 am

    I agree that something like SimpleXML would be better but if you want to get dirty, you can use lookaheads to try to match with the remaining characters.

    /piclink=\"(?<pic>.+)\".+urltarget=\"(?<target>.+)\".+urllink=\"(?<url>.*)\".+timevar=\"(?<delay>[^"]*)\"(?=(.*name=\"(?<name>[^"]*)\")?)(?=(.*alt=\"(?<alt>[^"]*)\")?).*/iU
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of a jQuery problem. Basically I have some functions that
Hey, I'm having some difficulty with CSS and IE6 compatibility. URL : http://bit.ly/dlX7cS Problem
Having a bit of problem with some syntax trying to insert HTML after an
I'm having a bit weird problem with WinForm which seems to refuse to close
I'm having a bit of a problem on one of my pages which is
I'm having a bit of a problem, I uploaded my Django project to a
I'm having a bit of a problem normalizing a UPC string code so that
I'm having a bit of an odd problem while trying to compile some code
I am having a bit of a problem with some mysql. I will try
Good evening everyone! I am having a bit of a problem and need some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.