如何使用 XSLT 2.0 和 REGEX(没有 \b 单词边界)在文本中查找单词? [英] How to find a word within text using XSLT 2.0 and REGEX (which doesn't have \b word boundary)?

查看:33
本文介绍了如何使用 XSLT 2.0 和 REGEX(没有 \b 单词边界)在文本中查找单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 匹配 "food" 并搜索 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 "food" 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 单词边界)在文本中查找单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆