• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

134
Views
How can we remove dots and back slashes along with word using regex

In my react hooks app while iterating the photo field, the src={photo}, it is coming as ..\public\images\photo-1654221497889.png I would like to remove,the word ..\public\ along with dots and back slashes using regex, but this is not working for me. I am expecting to get the resultant as follows images\photo-1654221497889.png

{
searchResults.slice(0, loadRequests).map(({id, photo, name }) => (
                        <div className='row'>
                            <div className="playerRow"> 
                                <label key={id}>
                                    <div className="row">
                                        <div className="checkStyle1">
                                            <input type="checkbox"></input>
                                        </div>
                                        <div className="plyPhoto">
                                            <img src={photo.replace(/[^..\public\]/g,"")}></img>
                                        </div>
                                         <div className="plyName">
                                            <div>{name}</div>
                                        </div>
                                    </div>
                                </label>
                            </div>  
                            
                        </div>  
                   ))}
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For this specific question, why not substring?

Specific regex: "^[.]+\\public\\"

General regex, keep only last two path: "^([^\\]*\\)*(.+\\)" and replace it with the second group: "$2"

If your want to learn regex, this is very concise resource: https://github.com/ziishaned/learn-regex

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error