使用正则表达式从rtf中选择带下划线的文本

发布于 2024-12-29 11:04:51 字数 376 浏览 2 评论 0原文

我想选择下一段带下划线的文本。您会看到 Richtextbox 的 rtf 具有以下带下划线文本的代码:

\ul\i0 hello friend\ulnone\i

但普通文本看起来像带下划线的。我想要做的是单击按钮,rtfbox 应该选择下一条带下划线的文本。一个示例文本是:

hello [friend your] house [looks] amazing.

想象一下方括号内的单词带有下划线。当我第一次单击按钮1时,应选择“您的朋友”,下次单击时应选择“看起来”。继续前进并继续选择应用程序类型。我知道这可以使用正则表达式来完成,但无法构建逻辑。

任何帮助将不胜感激。非常感谢:D

i want to select the next piece of text which is underlined. You see the rtf of a richtextbox has following code for an underlines text :

\ul\i0 hello friend\ulnone\i

But the normal text looks like underlined. What i want to do is on a click of button the rtfbox should select the next piece of text which is underlined. An example piece of text is :

hello [friend your] house [looks] amazing.

imagine the words within square brackets are underlined. When i first click button1 "friend your" should be selected and on next click "looks" should be selected. Kind of keep moving forward and keep selecting it type of application. I know this can be done using regex but can't build a logic.

Any help will be appreciated. Thanks a lot :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2025-01-05 11:04:51

正则表达式将是

Dim pattern As String = "\\ul\\i0\s*((?:(?!\\ulnone\\i).)+)\\ulnone\\i"

解释

\\ul\\i0              # the sequence "\ul\i0"
\s*                   # any number of white space
(                     # begin group 1:
  (?:                 #   non-capturing group:
    (?!               #     negative look-ahead ("not followed by..."):
      \\ulnone\\i     #       the sequence "\ulnone\i"
    )                 #     end negative look-ahead
    .                 #     match next character (it is underlined)
  )+                  #   end non-capturing group, repeat
)                     # end group 1 (it will contain all underlined characters)
\\ulnone\\i           # the sequence "\ulnone\i"

The regex would be

Dim pattern As String = "\\ul\\i0\s*((?:(?!\\ulnone\\i).)+)\\ulnone\\i"

Explanation

\\ul\\i0              # the sequence "\ul\i0"
\s*                   # any number of white space
(                     # begin group 1:
  (?:                 #   non-capturing group:
    (?!               #     negative look-ahead ("not followed by..."):
      \\ulnone\\i     #       the sequence "\ulnone\i"
    )                 #     end negative look-ahead
    .                 #     match next character (it is underlined)
  )+                  #   end non-capturing group, repeat
)                     # end group 1 (it will contain all underlined characters)
\\ulnone\\i           # the sequence "\ulnone\i"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文