正则表达式查找小写字母后跟大写字母

发布于 2024-12-25 00:03:05 字数 680 浏览 2 评论 0原文

我很难在 TextWrangler 中使用正则表达式 (Grep) 来查找小写字母后跟大写的出现情况。例如:

此公告表示欢迎学生

事实上,我想通过添加冒号来分割出现,使其成为意思:学生

我已经尝试过:

[a-z][A-Z]

但是这个表达式在TextWrangler中不起作用。

*编辑:这里是出现的确切上下文(我的意思是仅使用这些字体颜色)。*

<font color =#48B700>  - Stột jlăm wẻ baOne hundred and three<br></font>

<font color =#C0C0C0>     »» Qzống pguộc lyời ba yghìm fảy dyổiTo live a life full of vicissitudes, to live a life marked by ups and downs<br></font>

"baOne" and "dyổiTo" must be "ba: One" and "dyổi: To" 

有人可以帮忙吗?非常感谢。

I have difficulty using Regular Expression (Grep) in TextWrangler to find occurrences of lowercase letter followed by uppercase. For example:

This announcement meansStudents are welcome.

In fact, I want to split the occurrence by adding a colon so that it becomes means: Students

I have tried:

[a-z][A-Z]

But this expression does not work in TextWrangler.

*EDIT: here are the exact contexts in which the occurrences appear (I mean only with these font colors).*

<font color =#48B700>  - Stột jlăm wẻ baOne hundred and three<br></font>

<font color =#C0C0C0>     »» Qzống pguộc lyời ba yghìm fảy dyổiTo live a life full of vicissitudes, to live a life marked by ups and downs<br></font>

"baOne" and "dyổiTo" must be "ba: One" and "dyổi: To" 

Could anyone help? Many thanks.

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

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

发布评论

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

评论(4

兰花执着 2025-01-01 00:03:06

这是识别小写和大写字母的正确模式,但是,您需要在查找/替换对话框中检查匹配是否区分大小写。

That is the correct pattern for identifying lower case and upper case letters, however, you will need to check matching to be Case Sensitive within the Find/Replace dialogue.

樱&纷飞 2025-01-01 00:03:05

我确实相信(虽然手头没有 TextWrangler)您需要搜索 ([az])([AZ]) 并将其替换为: \1: \2< /code>

希望这有帮助。

I do believe (don't have TextWrangler at hand though) that you need to search for ([a-z])([A-Z]) and replace it with: \1: \2

Hope this helps.

带刺的爱情 2025-01-01 00:03:05

([az])([AZ]) 替换为 \1:\2 - 我没有 TextWrangler,但它可以在 Notepad++ 上使用

括号用于捕获data,在替换字符串中使用 \1 语法引用

Replace ([a-z])([A-Z]) with \1:\2 - I don't have TextWrangler, but it works on Notepad++

The parenthesis are for capturing the data, which is referred to using \1 syntax in the replacement string

中二柚 2025-01-01 00:03:05

这个问题由来已久,但我偶然发现了它,所以其他人也可能会这样做。 OP 对 Igor 回复的评论 澄清了如何描述任务(并且可以添加到描述中)。

要仅匹配 HTML 中那些特定于字体的行,请替换

(?<=)(.*?[az])([AZ])< /code>

\1: \2

说明:

  • (?<=[固定长度正则表达式]) 是一个 正向回顾 表示“如果我的匹配项前面有这个” >
  • (?:48B700|C0C0C0) 是一个未命名的组,仅匹配 2 种颜色。由于它们具有相同的长度,因此它们在后向工作(需要具有固定长度)
  • (.*?[az])([AZ]) 将匹配 之后的所有内容> 开始的字体标签一直到大写字母。
  • \1: \2 替换与 Igor 的响应中的相同,只是 \1 将匹配需要分隔的整个第一个字符串。

添加:

您的输入字符串包含特殊字符,并且您想要拆分的部分很可能以 1 结尾。在这种情况下,它们不会被 [az] 单独捕获。您需要添加一个字符游标来捕获您关心的所有字母,例如

(?<=<字体颜色=#(?:48B700|C0C0C0)>)(.*?[a-zḁ-ῼ])([AZ])

This question is ages old, but I stumbled upon it, so someone else might, as well. The OP's comment to Igor's response clarified how the task was meant to be described (& could have be added to the description).

To match only those font-specific lines of the HTML replace

(?<=<font color =#(?:48B700|C0C0C0)>)(.*?[a-z])([A-Z])

with \1: \2

Explanation:

  • (?<=[fixed-length regex]) is a positive lookbehind and means "if my match has this just before it"
  • (?:48B700|C0C0C0) is an unnamed group to match only 2 colours. Since they are of the same length, they work in a lookbehind (that needs to be of fixed length)
  • (.*?[a-z])([A-Z]) will match everything after the > of those begin font tags up to your Capital letters.
  • The \1: \2 replacement is the same as in Igor's response, only that \1 will match the entire first string that needs separating.

Addition:

Your input strings contain special characters and the part you want to split may very well end in one. In this case they won't be caught by [a-z] alone. You will need to add a character ranger that captures all the letters you care about, something like

(?<=<font color =#(?:48B700|C0C0C0)>)(.*?[a-zḁ-ῼ])([A-Z])

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