mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 11:15:50 +00:00
Create tagProcessor.js
This commit is contained in:
14
utils/tagProcessor.js
Normal file
14
utils/tagProcessor.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
function extractContentByTag(xmlString, tagName) {
|
||||||
|
const regex = new RegExp(`<${tagName}[^>]*>([\\s\\S]*?)<\\/${tagName}>`);
|
||||||
|
const match = xmlString.match(regex);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceContentByTag(xmlString, tagName, newContent) {
|
||||||
|
const regex = new RegExp(`(<${tagName}[^>]*>)[\\s\\S]*?(<\\/${tagName}>)`);
|
||||||
|
if (regex.test(xmlString)) {
|
||||||
|
return xmlString.replace(regex, `$1${newContent}$2`);
|
||||||
|
}
|
||||||
|
return xmlString;
|
||||||
|
}
|
||||||
|
export { extractContentByTag, replaceContentByTag };
|
||||||
Reference in New Issue
Block a user