正则表达式提取以@开头的单词

发布于 2024-08-24 05:27:10 字数 282 浏览 0 评论 0原文

尝试解析 SQL 字符串并提取参数。

例如:“从表中选择*,其中@Yr1和@Yr2之间的[年份]”

我想取出“@Yr1”和“@Yr2”

我尝试了很多模式,但没有一个有效,例如:

matches = Regex.Matches(sSQL, "\b@\w*\b")

matches = Regex.Matches(sSQL, "\b\@\w*\b")

有什么帮助吗?

Trying to parse an SQL string and pull out the parameters.

Ex: "select * from table where [Year] between @Yr1 and @Yr2"

I want to pull out "@Yr1" and "@Yr2"

I have tried many patterns, but none has worked, such as:

matches = Regex.Matches(sSQL, "\b@\w*\b")

and

matches = Regex.Matches(sSQL, "\b\@\w*\b")

Any help?

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

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

发布评论

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

评论(2

风情万种。 2024-08-31 05:27:10

您试图在 @ 之后而不是之前放置单词边界。也许这个:

\w(@[A-Z0-9a-z]+)

\w(@[^\s]+)

You're trying to put a word boundary after the @, rather than before. Maybe this:

\w(@[A-Z0-9a-z]+)

or

\w(@[^\s]+)

网白 2024-08-31 05:27:10

我会选择

/^|\s(@\w+)\s|$/

or 如果你不想包含@,

/^|\s@(\w+)\s|$/

尽管我也喜欢上面的 joel,所以也许是其中之一

/^|\s(@[^\s]+)\s|$/
/^|\s@([^\s]+)\s|$/

I would have gone with

/^|\s(@\w+)\s|$/

or if you didn't want to include the @

/^|\s@(\w+)\s|$/

though I also like joel's above, so maybe one of these

/^|\s(@[^\s]+)\s|$/
/^|\s@([^\s]+)\s|$/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文