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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:09:55+00:00 2026-06-09T07:09:55+00:00

I am attempting to parse a Wikipedia SQL dump with the Python regular expressions

  • 0

I am attempting to parse a Wikipedia SQL dump with the Python regular expressions library. The ultimate goal is to import this dump into PostgreSQL, but I know the apostrophes in strings need to be doubled, beforehand.

Every apostrophe in a string in this dump is preceded by a backwards slash, though, and I’d rather not remove the backwards slashes.

(42,’Thirty_Years\’_War’,33,5,0,0)

Using the command

re.match(".*?([\w]+?'[\w\s]+?).*?", line)

I cannot identify the apostrophe in the middle of ‘Thirty_Years\’_War’, when ‘line’ is parsed from a text file.

For comparison, these lines work fine when parsed (sans the last line).

The person’s car

The person’s car’s gasoline

Hodges’ Harbrace Handbook

‘Hodges’ Harbrace Handbook’

portspeople’,1475,29,0,0),(42,’Thirty_Years\’_War’,33,5,0,0)

Correct and expected output (sans the last line):

The person”s car

The person”s car”s gasoline

Hodges” Harbrace Handbook

(‘Hodges” Harbrace Handbook’)

portspeople’,1475,29,0,0),(42,’Thirty_Years\’_War’,33,5,0,0)

Using the command

re.match(".*?([\w\\]+?'[\w\s]+?).*?", line)

breaks it.

The person”s car

The person””s car””s gasoline

Hodges” Harbrace Handbook

(””””Hodges”””” Harbrace Handbook””””)

portspeople””””””””,1475,29,0,0),(42,””””””””Thirty_Years\””””””””_War””””””””,33,5,0,0)

Is it stuck in some sort sort of loop? What is the correct regex code to use?

I am not thinking about SQL injection attacks because this script is only going to be used for parsing dumps of Wikipedia articles (that don’t contain examples of SQL injection attacks).

  • 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-09T07:09:58+00:00Added an answer on June 9, 2026 at 7:09 am

    If the dump consists of things like the string you provided, you could try something like this:

    re.findall(r"[^,\(\)]+")
    

    Where the character class contains all known separators.

    EDIT: Only use regex for parsing when there is no better way 🙂

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

Sidebar

Related Questions

I'm attempting to parse an Oracle trace file using regular expressions. My language of
I am attempting to parse (in Java) Wikimedia markup as found on Wikipedia. There
I am attempting to parse a XML file using Javascript and I'm running into
I am attempting to parse an XML file using python expat. I have the
I'm attempting to parse load a rather complicated XML schema into a Schema object
I'm attempting to parse SQL using the TSql100Parser provided by microsoft. Right now I'm
I am attempting to parse html data from a website using BeautifulSoup for python.
I am attempting to parse the following String into a DateTime object in c#:
I'm attempting to parse newlines from pasted text from the clipboard into a single-lined
I am attempting to parse a string like the following using a .NET regular

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.