Closed. This question needs to be more
const s = "Floor_f4e88618-22a5-11ec-9621-0242ac130002_Location";
const result = s.match(/Floor_(.*?)_Location/)[1];
console.log(result);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
2) Using Regex /(?<=_).*?(?=_)/
const s = "Floor_f4e88618-22a5-11ec-9621-0242ac130002_Location";
const result = s.match(/(?<=_).*?(?=_)/)[0];
console.log(result);
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
3) You can achieve the same result using slice
const s = "Floor_f4e88618-22a5-11ec-9621-0242ac130002_Location";
const result = s.slice(s.indexOf("_") 1, s.lastIndexOf("_"));
console.log(result);
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
CodePudding user response:
You can also solve this without a regex, if you have this strict format:
const test = "Floor_f4e88618-22a5-11ec-9621-0242ac130002_Location"
const uuid = test.split('_')[1]
console.log(uuid)
<iframe name="sif4" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
This benefits from the fact that uuid
doesn't contain a _