问题描述
我正在尝试使用 REGEX 扫描一串单词并在 XSLT 2.0 样式表中查找特定单词(不区分大小写)的存在.
I am attempting to scan a string of words and look for the presence of a particular word(case insensitive) in an XSLT 2.0 stylesheet using REGEX.
我有一个单词列表,我希望迭代并确定它们是否存在于给定的字符串中.
I have a list of words that I wish to iterate over and determine whether or not they exist within a given string.
我想匹配给定文本中任意位置的一个词,但我不想匹配内一个词(即搜索foo
应该 not 匹配 "foo
d" 并搜索 bar
应该不匹配rebar
").
I want to match on a word anywhere within the given text, but I do not want to match within a word (i.e. A search for foo
should not match on "foo
d" and a search for bar
should not match on "rebar
").
XSLT 2.0 REGEX 没有字边界(\b
),所以我需要尽可能地复制它.
XSLT 2.0 REGEX does not have a word boundary(\b
), so I need to replicate it as best I can.
推荐答案
您可以使用交替来避免重复:
You can use alternation to avoid repetition:
<xsl:if test="matches($prose, concat('(^|\W)', $word, '($|\W)'),'i')">
这篇关于如何使用 XSLT 2.0 和 REGEX(没有 \b 单词边界)在文本中查找单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!