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

  • SEARCH
  • Home
  • 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 6974695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:16:16+00:00 2026-05-27T17:16:16+00:00

Regular expressions are a sure way to bring me back to earth. I don’t

  • 0

Regular expressions are a sure way to bring me back to earth. I don’t think I’ve ever produced one without help, so here is another cry for help. Here’s the example input:

{{Taxobox | name = Impala | status = LC | status_system = IUCN3.1 |
status_ref = {{IUCN2008|assessors=IUCN SSC Antelope
Specialist Group |year=2008|id=550|title=Aepyceros
melampus|downloaded=18 January 2009}} Database entry includes a brief
justification of why this species is of least concern | trend =
stable | image = Serengeti Impala3.jpg | image_caption= Young male
Impala in [[Serengeti]], [[Tanzania]] | image2=Female_impala.jpg |
image2_caption= Female Impala in [[Mikumi National Park]],
[[Tanzania]] | regnum = [[Animal]]ia | phylum = [[Chordate|Chordata]]
| classis = [[Mammal]]ia | ordo = [[Even-toed ungulate|Artiodactyla]]
| familia = [[Bovid]]ae | subfamilia = ”’Aepycerotinae”’ |
subfamilia_authority = [[John Edward Gray|Gray]], 1872 | genus =
””’Aepyceros””’ | genus_authority = [[Carl Jakob
Sundevall|Sundevall]], 1847 | species = ””’A. melampus””’ |
subdivision_ranks = Subspecies | subdivision = * ”[[Aepyceros
melampus petersi|A. m. petersi]]”
* ”A. m. melampus” | range_map=Leefgebied_impala.JPG | range_map_caption=Range map | binomial = ”Aepyceros melampus” |
binomial_authority = ([[Martin Lichtenstein|Lichtenstein]], 1812) |
range_map = Impala.png | range_map_caption = Distribution of the
Impala
Red =A. m. melampus
Blue = A. m. petersi }}

Sorry I can’t get this formatted in a better way. It’s a long string with no newlines in them. It is essentially a set of name-value pairs. Each pair the format:

pipe space attributename space equals space attributevalue space

There’s no obvious end character to a pair, other than the pipe of the next pair.

What I’d like to do is to turn this into an associative array in PHP. For what it’s worth, here’s my attempt of at least trying to find some matches:

$pattern = "/\|([^=|^.]*)=([^\|]*)|/s";
if (preg_match_all($pattern, $pagecontent, $matches)) {
var_dump($matches);
} else echo "no match!";

It’s way of so don’t pay too much attention to it. I’m hoping for some regex masters to help me out here.

  • 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-05-27T17:16:17+00:00Added an answer on May 27, 2026 at 5:16 pm

    You need to isolate the contained string from the {{ and }} delimiters before you try to extract the pairs. This will fail on your example due to what looks like nested grouping with status_ref={{...}}. You will need preg_replace_callback and a (?R) pattern for that.

    A regex like this might work for the pairs itself however:

    "/(?<=  ^ | \|)  # start, of string, or after any |
      \s*(\w+)       # name
      (?:\s*=\s*(    #  =
      \{\{.*?\}\}    # {{....}}
      | \[\[.*?\]\]  # [[...]]
      | \(.*?\)      # (...)
      | [^|]+) )?    # plain values
     /sx"
    

    It will give you an associative array with:

    $array = array_combine($matches[1], $matches[2]);
    

    With the lonely name tokens not getting an associated value of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty sure regular expressions are the way to go, but my head hurts
Using regular expressions in C#, is there any way to find and remove duplicate
I have two regular expressions: /\/(\w\w+)/g /(^\w\w+)/g and am wondering if there's any way
Need some regular expressions help. So far I have my code working to allow
I'm not very good with regular expressions, so I want to make sure I'm
I need help using regular expressions. Ihave read the Java Regex notes, but could
I just don't seem to have any luck with regular expressions ! I've written
I'm not sure how to use regular expressions in a function so that I
I'm very new to Regular Expressions, but I thought it'd be the best way
As the name suggests we may think that regular expressions can match regular languages

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.