Javascript 验证所见即所得的空白
我试图使用正则表达式验证所见即所得编辑器,当它有空的空格时,输入key,spaces,它将返回true 混合空格和enter键的示例结果为:Javascript 验证所见即所得的空白,javascript,regex,wysiwyg,Javascript,Regex,Wysiwyg,我试图使用正则表达式验证所见即所得编辑器,当它有空的空格时,输入key,spaces,它将返回true 混合空格和enter键的示例结果为: <p> </p> <p> </p> <p> </p> <p> </p> ..
<p> </p>
<p> </p>
<p> </p>
<p> </p>
...
(not that the line number of <p> tag is not fixed, it depends on how many enter key i press)
注:
有时标签之间有空格,有时没有。
标签的数量不是固定的,它取决于我按了多少回车键。
我需要拿出一个上述标准的正则表达式,但我面临的困难在哪里
标记之间的打开和关闭空格
一组或多组标签
我自己试过的正则表达式:
/^ +\t*$
分离的标记的我的代码段测试结果:
->不匹配
->匹配
->不匹配
->matched希望你想要这样的东西。 理解replaceAll正则表达式要比添加更复杂的正则表达式容易得多。 只需执行下面的示例就可以看到它的作用 //替换所有原型功能 String.prototype.replaceAll=函数搜索,替换{ var目标=此; 返回target.replacenew RegExpsearch,'g',replacement; }; //用于检测内容是否为空的函数 函数isContentEmptytext{ text=text.replaceAll。 替换全部。 全部替换。 全部更换,.修剪; return text.length==0?true:false; } //空测试 var emptyText=document.getElementByIdempty.innerHTML; console.logIs[id=empty]内容为空:,isContentEmptyemptyText; //非空测试 var notEmptyText=document.getElementByIdnot-empty.innerHTML; console.logIs[id=not empty]内容为空:,isContentEmptynotEmptyText; 内容
因此,您提供的代码片段将验证为false或true?请尝试/^?:|[^\S\r\n]*$/gm