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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:31:48+00:00 2026-05-12T13:31:48+00:00

I need to do a find and replace on about 45k lines of a

  • 0

I need to do a “find and replace” on about 45k lines of a CSV file and then put this into a database.

I figured I should be able to do this with PHP and preg_replace but can’t seem to figure out the expression…

The lines consist of one field and are all in the following format:

“./1/024/9780310320241/SPSTANDARD.9780310320241.jpg” or “./t/fla/8204909_flat/SPSTANDARD.8204909_flat.jpg”

The first part will always be a period, the second part will always be one alphanumeric character, the third will always be three alphanumeric characters and the fourth should always be between 1 and 13 alphanumeric characters.

I came up with the following which seems to be right however I will openly profess to not knowing very much at all about regular expressions, it’s a little new to me! I’m probably making a whole load of silly mistakes here…

$pattern = "/^(\.\/[0-9a-zA-Z]{1}\/[0-9a-zA-Z]{3}\/[0-9a-zA-Z]{1,13}\/)$/";
$new = preg_replace($pattern, " ", $i);

Anyway any and all help appreciated!

Thanks,
Phil

  • 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-12T13:31:48+00:00Added an answer on May 12, 2026 at 1:31 pm

    I’m not sure I understand what you’re asking. Do you mean every line in the file looks like that, and you want to process all of them? If so, this regex would do the trick:

    '#^.*/#' 
    

    That simply matches everything up to and including the last slash, which is what your regex would do if it weren’t for that rogue ‘$’ everyone’s talking about. If there are other lines in other formats that you want to leave alone, this regex will probably suit your needs:

    '#^\./\w/\w{3}/\w{1,13}/#"
    

    Notice how I changed the regex delimiter from ‘/’ to ‘#’ so I don’t have to escape the slashes inside. You can use almost any punctuation character for the delimiters (but of course they both have to be the same).

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

Sidebar

Related Questions

I need to perform a find and replace using XSLT 1.0 which is really
I need to do a find and replace in Notepad++ of Err.Number, canBeAnything, canBeAnything,
I need to do a regex find and replace on all the files in
I have an excel sheet which has about 150,000 records, operations like find replace,
I need to do a find and replace (specific to one column of URLs)
I have the following code in about 300 HTML files, I need to replace
I have an array of words I need to do a find-and-replace by regex
I know there are multiple questions about this same question but I couldn't find
I have a file that has over 200 lines in this format: name old_id
I find this selector format cumbersome if I need to use it often: $('[name=someElementName]').val()

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.