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>
))}
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