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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:04:08+00:00 2026-05-12T19:04:08+00:00

Hey guys, given a data set in plain text such as the following: ==Events==

  • 0

Hey guys, given a data set in plain text such as the following:

==Events==
* [[312]] – [[Constantine the Great]] is said to have received his famous [[Battle of Milvian Bridge#Vision of Constantine|Vision of the Cross]].
* [[710]] – [[Saracen]] invasion of [[Sardinia]].
* [[939]] – [[Edmund I of England|Edmund I]] succeeds [[Athelstan of England|Athelstan]] as [[King of England]].
*[[1275]] – Traditional founding of the city of [[Amsterdam]].
*[[1524]] – [[Italian Wars]]: The French troops lay siege to [[Pavia]].
*[[1553]] – Condemned as a [[Heresy|heretic]], [[Michael Servetus]] is [[burned at the stake]] just outside [[Geneva]].
*[[1644]] – [[Second Battle of Newbury]] in the [[English Civil War]].
*[[1682]] – [[Philadelphia]], [[Pennsylvania]] is founded.

I would like to end up with an NSDictionary or other form of collection so that I can have the year (The Number on the left) mapping to the excerpt (The text on the right). So this is what the ‘template’ is like:

*[[YEAR]] – THE_TEXT

Though I would like the excerpt to be plain text, that is, no wiki markup so no [[ sets. Actually, this could prove difficult with alias links such as [[Edmund I of England|Edmund I]].

I am not all that experienced with regular expressions so I have a few questions. Should I first try to ‘beautify’ the data? For example, removing the first line which will always be ==Events==, and removing the [[ and ]] occurrences?

Or perhaps a better solution: Should I do this in passes? So for example, the first pass I can separate each line into * [[710]] and [[Saracen]] invasion of [[Sardinia]]. and store them into different NSArrays.

Then go through the first NSArray of years and only get the text within the [[]] (I say text and not number because it can be 530 BC), so * [[710]] becomes 710.

And then for the excerpt NSArray, go through and if an [[some_article|alias]] is found, make it only be [[alias]] somehow, and then remove all of the [[ and ]] sets?

Is this possible? Should I use regular expressions? Are there any ideas you can come up with for regular expressions that might help?

Thanks! I really appreciate it.

EDIT: Sorry for the confusion, but I only want to parse the above data. Assume that that’s the only type of markup that I will encounter. I’m not necessarily looking forward to parsing wiki markup in general, unless there is already a pre-existing library which does this. Thanks again!

  • 1 1 Answer
  • 1 View
  • 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-12T19:04:08+00:00Added an answer on May 12, 2026 at 7:04 pm

    This code assumes you are using RegexKitLite:

    NSString *data = @"* [[312]] – [[Constantine the Great]] is said to have received his famous [[Battle of Milvian Bridge#Vision of Constantine|Vision of the Cross]].\n\
        * [[710]] – [[Saracen]] invasion of [[Sardinia]].\n\
        * [[939]] – [[Edmund I of England|Edmund I]] succeeds [[Athelstan of England|Athelstan]] as [[King of England]].\n\
        *[[1275]] – Traditional founding of the city of [[Amsterdam]].";
    
        NSString *captureRegex = @"(?i)(?:\\* *\\[\\[)([0-9]*)(?:\\]\\] \\– )(.*)"; 
    
        NSRange captureRange;
        NSRange stringRange;
        stringRange.location = 0;
        stringRange.length = data.length;
    
        do 
        {
            captureRange = [data rangeOfRegex:captureRegex inRange:stringRange];
            if ( captureRange.location != NSNotFound )
            {
                NSString *year = [data stringByMatching:captureRegex options:RKLNoOptions inRange:stringRange capture:1 error:NULL];
                NSString *textStuff = [data stringByMatching:captureRegex options:RKLNoOptions inRange:stringRange capture:2 error:NULL];
                stringRange.location = captureRange.location + captureRange.length;
                stringRange.length = data.length - stringRange.location;
                NSLog(@"Year:%@, Stuff:%@", year, textStuff);
            }
        }
        while ( captureRange.location != NSNotFound );
    

    Note that you really need to study up on RegEx’s to build these well, but here’s what the one I have is saying:

    (?i)
    

    Ignore case, I could have left that out since I’m not matching letters.

    (?:\* *\[\[)
    

    ?: means don’t capture this block, I escape * to match it, then there are zero or more spaces (” *”) then I escape out two brackets (since brackets are also special characters in a regex).

    ([0-9]*)
    

    Grab anything that is a number.

    (?:\]\] \– )
    

    Here’s where we ignore stuff again, basically matching ” – “. Note any “\” in the regex, I have to add another one to in the Objective-C string above since “\” is a special character in a string… and yes that means matching a regex escaped single “\” ends up as “\\” in an Obj-C string.

    (.*)
    

    Just grab anything else, by default the RegEX engine will stop matching at the end of a line which is why it doesn’t just match everything else. You’ll have to add code to strip out the [[LINK]] stuff from the text.

    The NSRange variables are used to keep matching through the file without re-matching original matches. So to speak.

    Don’t forget after you add the RegExKitLite class files, you also need to add the special linker flag or you’ll get lots of link errors (the RegexKitLite site has installation instructions).

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

Sidebar

Related Questions

No related questions found

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.