You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sitecore技术问询:如何用正则参数准确检测触发FatalError的script标签

Fixing Your Script Tag Detection Issue

Let's break down what's going wrong here and how to fix it:

The Core Problem

Your current regex ^<script[^>]*>$ uses ^ and $ anchors, which tell the regex engine to match the entire string exactly as a single opening <script> tag (like <script> or <script src="foo.js">).

But here's the contradiction:

  • You expect <script>Test</script> to trigger an error, but this string doesn't match your regex (it ends with </script>, not just >)
  • Worse, Test is also triggering an error, which suggests your tool's matching logic might be reversed (e.g., it's throwing an error when the text doesn't match the pattern, instead of when it does)

Solutions Based on Your Exact Need

1. If you want to block any text containing a <script> tag (opening or full block)

If your goal is to flag any text that includes a script tag (even partial), drop the ^ and $ anchors. Use this regex:

<script[^>]*>

URL-encoded for your Parameters field:

Pattern=&lt;script[^&gt;]*&gt;&amp;Text=Field "script" is not a valid entry.&amp;Result=FatalError

This will match any opening <script> tag in the text, so <script>Test</script> will trigger the error (as expected), and Test won't.

2. If you want to strictly block full <script>...</script> tag pairs

For tighter control (only flag complete script blocks), use a non-greedy regex to match from the opening tag to the first closing tag:

<script[^>]*>.*?</script>

URL-encoded:

Pattern=&lt;script[^&gt;]*&gt;.*?&lt;/script&gt;&amp;Text=Field "script" is not a valid entry.&amp;Result=FatalError

This avoids matching across multiple script tags if they exist, and only flags text that contains a full script block.

3. Double-check your tool's matching logic

If neither of the above fixes work, confirm whether your tool throws an error when the text matches the pattern or when it doesn't. If it's the latter (error on mismatch), you'll need a negative regex to ensure the text doesn't contain script tags:

^(?!.*<script[^>]*>.*?</script>).*$

This regex ensures the text has no full script blocks — if it does, it won't match, triggering the error.

内容的提问来源于stack exchange,提问作者Zakayen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:18:38