正则表达式问题

发布于 2024-08-03 10:11:21 字数 276 浏览 3 评论 0原文

我需要一些帮助来解决我遇到的一些正则表达式问题。首先,双引号 "

"" 之间的任何内容都需要匹配。下一个问题我需要匹配以 ' 开头的任何内容,直到行尾 \n

没有任何想法可以匹配。

我已经尝试了各种方法,但似乎 意识到我需要将引号放在 "" 之间。

I need some help with some regular expression problems I am having. First off, double quotes ".

Anything between "" needs to be matched. Next problem I need to match anything that starts with a ' till the end of a line \n or <br />.

I've tried all sorts, but nothing seems to match it. Any ideas?

Sorry guys, just realised I need the quotes to be between " and ".

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

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

发布评论

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

评论(5

∞觅青森が 2024-08-10 10:11:21

简单化:

"[^"]*"

将匹配双引号之间的任何内容,尽管它不适用于转义双引号,例如

"Abc\"Def"

对于 EOL 的单引号,您可以使用

'.*$

更新:Sylverdrag's made a valid point;匹配您需要的引号

"([^"]*)"

,然后获取匹配的第一个子组。我看到问题已经更新,提到应该使用 " - 我的答案可以很容易地适应这一点。

Simplistic:

"[^"]*"

will match anything between double quotes, though it won't work with escaped double quotes such as

"Abc\"Def"

For the single-quote to EOL, you can use

'.*$

Update: Sylverdrag's made a valid point; to match between the quotes you'd need

"([^"]*)"

and then get the first subgroup of the match. I see the question's been updated to mention that " should be used - my answer can be adapted to this easily enough.

舟遥客 2024-08-10 10:11:21

尝试:

双引号:

\"\;(.*?)\"\;

单引号直到行尾或

\'(.*)(\<br|$)

Try:

Double quotes:

\"\;(.*?)\"\;

Single quote till end of line or <br/>:

\'(.*)(\<br|$)
沩ん囻菔务 2024-08-10 10:11:21

引号之间的任何内容

/"(.*)"/

从 ' 到行尾的

/'(.*)$/

anything between quotes

/"(.*)"/

from ' till end of line

/'(.*)$/
简美 2024-08-10 10:11:21

尝试这些正则表达式:

/"(.*?)"/s
/'.*?(?=\n|<br \/>)/m

Try these regular expressions:

/"(.*?)"/s
/'.*?(?=\n|<br \/>)/m
三寸金莲 2024-08-10 10:11:21

为了变得更时髦一点,只匹配双引号内的内容,而不匹配引号本身:

(?<=").*?(?=")

To get a bit more funky and match only what is inside the double quotes but not the quotes themselves:

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