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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:37:13+00:00 2026-06-10T15:37:13+00:00

So I looked around on Stackoverflow and I understand finding and replacing text works

  • 0

So I looked around on Stackoverflow and I understand finding and replacing text works something like this:

perl -pi -w -e 's/www.example.com/www.pressbin.com/g;' *.html

However, what if the text I want to find and replace is a filepath that has slashes? How do I do it then?

perl -pi -w -e 's/path/to/file/new/path/to/file/g;' *.html
  • 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-10T15:37:15+00:00Added an answer on June 10, 2026 at 3:37 pm

    With perl regexes, you can use any character except spaces as regex delimiter, although

    • Characters in \w (so s xfooxbarx is the same as s/foo/bar/) and
    • Question marks ? (implicitly activates match-only-once behaviour, deprecated) and
    • single quotes '...' (turns of variable interpolation)

    should be avoided. I prefer curly braces:

    perl -pi -w -e 's{path/to/file}{new/path/to/file}g;' *.html
    

    The delimiting character may not occur inside the respective strings, except when they are balanced braces or properly escaped. So you could also say

    perl -pi -w -e 's/path\/to\/file/new\/path\/to\/file/g;' *.html
    

    but that is dowrnright ugly.

    When using braces/parens etc there can be whitespace between the regex and the replacement, allowing for beatiful code like

    $string =~ s {foo}
                 {bar}g;
    

    Another interesting regex option in this context is the quotemeta function. If your search expression contains many characters that would usually be interpreted with a special meaning, we can enclose that string inside \Q...\E. So

    m{\Qx*+\E}
    

    matches the exact string x*+, even if characters like *, ‘+’ or | etc. are included.

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

Sidebar

Related Questions

I have looked around on Google and StackOverflow for the answer to this question,
I understand why this is happening but I need a work-around. I looked into
I'm facing a weird problem. I looked around all over stackoverflow.com and elsewhere, but
I looked around on StackOverflow and it looks like all of the questions related
I've looked around StackOverflow and other places (including Git documentation) and just cannot get
I've looked around on stackoverflow for a similar question, but haven't found exactly what
I looked around but haven't found an answer to this. I have a CentOS
I looked around and couldn't find it! Maybe I didn't look hard enough,but this
I have looked around like crazy but don't get a real answer. I got
I've looked around Stack Overflow for an answer to this, but nowhere seems to

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.