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 7785307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:14:04+00:00 2026-06-01T20:14:04+00:00

My question is a little wordy so I’ll try to explain with an example.

  • 0

My question is a little wordy so I’ll try to explain with an example.

I have a file that’s somewhat similar to XML that I need to parse, though not exactly. Elements in the file generally show up similar to XML format, like

<person><greeting>hello</greeting><goodbye>bye</goodbye></person>

I wanted to split up the file into individual sets of tags, so that one element would be

<greeting>hello</greeting>

and another would be

<goodbye>bye</goodbye>

Naturally for an empty element, <person> and </person> will end up being their own elements, I’m completely OK with that because of how I want to parse the file as a whole.

The issue I’m running into is how best to split the whole file into an array, because there’s no newlines at all in the file, it’s written out as you see it. I tried doing it like this

my @array = split(/(><)/, $file)

but the issue is that it doesn’t preserve the angle braces as a part of the associated tag, but separates them out. Is there a way for me to split the file between the > and < characters?

  • 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-01T20:14:05+00:00Added an answer on June 1, 2026 at 8:14 pm

    I am not sure if this is the best solution, but to answer your question directly, you can split between the angles using lookbehind and lookahead assertions.

    my @array = split(/(?<=>)(?=<)/, $file)
    

    The difference is. that they do not consume the >< part, they match the position in between.

    Another idea would be to use a backreference to match the correct (it matches the first closing tag with this name, that is wrong when identical tags are nested) closing tag, something like this

    <([^>]*)>(.*?)</\1>
    

    See it here on Regexr

    You have two references in this regex. The first is used to match the closing tag, and in the second you will find the content of the tag.

    Of course it will match at first the “person” tag, but you will find the other tags in $2. You would have to use the regex recursively on $2 till the result is an empty array.

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

Sidebar

Related Questions

I have this little question that's been on my mind for a while now.
A small - little question. I have seen many application having buttons like following.
I have little question about how web browser retrieve webpage? I know this User
I have little question. I found this on internet: Type t = typeof(MyClass); MethodInfo[]
I have a little question to community. Does ASP.NET MVC allow to execute an
i have a little question, regarding to slideup and slidedown, the problem is in
I have only a little question: Why the CFPreferences-API creates multiple files in my
Following the good jQuery Plugins/Authoring instructions I have a little question (function($){ // Default
A little back story : I have small application that will use Word to
I've a little question about decoding special characters from a JSon result (in my

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.