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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:32:06+00:00 2026-05-25T19:32:06+00:00

I have a pipe-delimited dump file from an SQL Server, and I want to

  • 0

I have a pipe-delimited dump file from an SQL Server, and I want to import it into MySQL. The lines are delimited by \r\n, and that sequence also occurs in some fields! So I want to use a regular expression to find the actual lines and make an INSERT statement out of them.

However, I’m having trouble including the delimiter in my match string. I thought using PREG_SPLIT_DELIM_CAPTURE would do the trick but apparently I’m doing something wrong. My delimiter is three spaces followed by three numbers, which is actually the id that I need for the row:

$ cat test.php
<?
$string = '   897|a|Hello\r\n   583|b|Line\r\nBreak\r\n   332|c|Yet\r\nMore\r\nLine\r\nBreaks\r\n';

$lines = preg_split( '/   \d{3}\|/', $string, NULL, PREG_SPLIT_DELIM_CAPTURE);
print_r($lines);

$ php test.php
Array
(
    [0] => 
    [1] => a|Hello\r\n
    [2] => b|Line\r\nBreak\r\n
    [3] => c|Yet\r\nMore\r\nLine\r\nBreaks\r\n
)

My delimiters are missing.

$ php -v
PHP 5.3.3-7+squeeze1 with Suhosin-Patch (cli) (built: Mar 18 2011 17:22:52) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

What am I doing wrong, or how do I get what I want?

  • 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-25T19:32:07+00:00Added an answer on May 25, 2026 at 7:32 pm

    You need to group your delimiter into parenthesis, or else the _DELIM_CAPTURE will have no effect.

    $lines = preg_split( '/   (\d{3}\|)/', $string, NULL, PREG_SPLIT_DELIM_CAPTURE);
    

    Here, the manual mentions it en passant as flag description:

    PREG_SPLIT_DELIM_CAPTURE
    If this flag is set, parenthesized expression in the delimiter pattern will be captured and returned as well.

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

Sidebar

Related Questions

I have a flat file that is pipe delimited and an database table. I
Here's the situation, I have a text file that is pipe-delimited and one of
I have a form that will ultimately create a pipe delimited text file. The
hi guys i have two pipe delimited files,first file contains 1000 records and second
I have a file with fields separated by pipe characters and I want to
I have to dump a large database over a network pipe that doesn't have
Scenario: I have a text file that has pipe (as in the | character)
I have a pipe delimited feed file which has several fields. Since I only
I have the need to parse through a large pipe-delimited file to count the
I have a Perl script inserting data into Postgres according to a pipe delimited

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.