Use JavaScript to detect whether the closing tags of [] and ┏┓ in the content are complete

function checkTags(text) {
  const stack = [];
  const regex = /[【┏┓】]/g;
  let match;

  while ((match = regex.exec(text)) !== null) {
    if (match[0] === '【' || match[0] === '┏') {
      stack.push(match[0]);
    } else if (match[0] === '】') {
      if (stack.length === 0 || stack.pop() !== '【') {
        return false;
      }
    } else if (match[0] === '┓') {
      if (stack.length === 0 || stack.pop() !== '┏') {
        return false;
      }
    }
  }

  return stack.length === 0;
}

const text = '不【机构名称-1】能出现【机构名称-1】极限【机构名称-1】词和违禁词┏关键词┓';
const isTagsClosed = checkTags(text);
console.log(isTagsClosed);

Guess you like

Origin blog.csdn.net/weixin_38822843/article/details/131966100