JSFiddle - React, Tailwind, and code Playground

by dshilkret

JavaScript

const inputString = "/Web/GetFileByServerRelativeUrl('/dtech/something/ServiceNowDev7/Dev7Lib1/INC0000003/Dog Body Language Dog Body Language Dog Body Language Dog Body Language Dog Body Language Dog Body Language 2.pdf')/listitemallfields";

// Using match to find the content within the first pair of parentheses
const matchedContent = inputString.match(/\('(.*?)'\)/);

let capturedValue = '';
if (matchedContent && matchedContent[1]) {
  capturedValue = matchedContent[1]; // This captures the value inside the single quotes
}

// Proceeding with the replacement while removing the single quotes
const resultString = inputString.replace(/\('.*?'\)/, "(@relativeUrl)");

console.log("Captured Value:", capturedValue);
console.log("Result String:", resultString);





/* const inputString = "/Web/GetFileByServerRelativeUrl('/dtech/something/ServiceNowDev7/Dev7Lib1/INC0000003/Dog Body Language Dog Body Language Dog Body Language Dog Body Language Dog Body Language Dog Body Language 2.pdf')/listitemallfields";

// Using a regular expression to match everything between the first '(' and the last ')', and replace it with '&relativeUrl'
const resultString = inputString.replace(/\(.*?\)/, "('@relativeUrl')");

console.log(resultString);

const inputString1 = "/Web/GetFileByServerRelativeUrl('/dtech/something/ServiceNowDev7/Dev7Lib1/INC0000003/Dog Body Language Dog Body Language Dog Body Language Dog Body Language Dog Body Language Dog Body Language 2.pdf')/listitemallfields";

// Using a regular expression to match everything between the first '(' and the first ')', and replace it with @relativeUrl without single quotes
const resultString1 = inputString1.replace(/\('.*?'\)/, "(@relativeUrl)");

console.log(resultString1); */