一定数量字符的正则表达式

发布于 2024-10-28 04:28:41 字数 207 浏览 7 评论 0原文

我正在尝试使用 TextWrangler 更改大量 URL,那些以 m.htm 结尾的 URL 应该会丢失 m,但前提是文件名中的字符总数为7. 字符数较少的不要更改。

我已经尝试过

/.*?{7}m.htm/

,但不起作用...

解决方案是什么?

I'm trying to change a lot of URLs with TextWrangler, those ending with m.htm should lose the m, but only if the total number of characters in the filename is 7. Those with fewer characters should not be changed.

I've tried

/.*?{7}m.htm/

but it doesn't work...

What is the solution?

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

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

发布评论

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

评论(2

靖瑶 2024-11-04 04:28:41

替换

href="([^"]*)\/(.{6})m.htm([^"]*)"

含义: href=" 后跟任何非 " 字符,直到 / (越晚越好:贪婪),然后是 6 个字符,后跟一个m,然后是任何非 " 字符。

含义

href="\1\/\2.htm\3"

\1 = [^"]*
\2 = .{6}
\3 = [^"]*

示例

<a href="google.com/foo/bar/urzadjm.htm">testM</a> 
\1 : google.com/foo/bar
\2 : urzadj
\3 : <empty>

如果文件可以是 htmphp,我建议将 .htm 替换为 (.htm|.php) (!警告反向引用数字更改!)

Replace

href="([^"]*)\/(.{6})m.htm([^"]*)"

Meaning : href=" followed by any non " character until a / (the latest the better: greedy) then 6 character followed by a m, then any non " character.

By

href="\1\/\2.htm\3"

Meaning :

\1 = [^"]*
\2 = .{6}
\3 = [^"]*

Example

<a href="google.com/foo/bar/urzadjm.htm">testM</a> 
\1 : google.com/foo/bar
\2 : urzadj
\3 : <empty>

If files can be htm and php, I suggest to replace .htm by (.htm|.php) (!Warning to back-references change in numbers!)

聆听风音 2024-11-04 04:28:41

可能是

/\b.{6}m\.htm/

即从单词边界开始,后跟任意 6 个符号,最后是 m.htm。

May be

/\b.{6}m\.htm/

That is, starting on the word boundary, followed by any 6 symbols, followed by m.htm.

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