如何在 TextMate 中搜索并替换包含某些变量的代码片段?

发布于 2024-07-15 01:37:09 字数 1101 浏览 8 评论 0原文

我有一个包含 49 个文件夹的项目,每个文件夹都有一个名为 index.php 的文件

所有 index.php 文件几乎相同,除了一部分根据其所在的文件夹而变化

<?php include_once("/home/bgarch/public_html/galleryheader.html"); ?>
<?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?>

</head>
<body>


<div class="header">
    <?php include_once("/home/bgarch/public_html/header.html"); ?>
</div>

<div class="clear"></div>

<div class="displaywrapper">
    <?php include_once("content.html"); ?>
</div></div>    

<div class="clear"></div>

<?php include_once("/home/bgarch/public_html/footer.html"); ?>

。第二行,上面写着:“../culture/..”文化一词是变量,并且根据它所在的文件夹而有所不同。

我需要知道的是执行“查找/替换项目中的所有内容”会自动将每个“index.php”文件中的所有文本替换为以下内容“

<?php include_once("http://www.bgarchitect.co.nz/subPage/index.php"); ?>

我花了过去 2 小时试图找出正则表达式来完成此任务,但到目前为止尚未成功。 也许不能这样做?

不管怎样,我想我应该在这里问一个问题,希望它实际上比我预期的要容易得多。 因此,非常感谢任何帮助/指针/提示或技巧。

谢谢阅读, 詹尼斯

I have a project that includes 49 folders, each one has a file called index.php

All index.php files are almost the same except for one part that changes depending on the folder it is in.

<?php include_once("/home/bgarch/public_html/galleryheader.html"); ?>
<?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?>

</head>
<body>


<div class="header">
    <?php include_once("/home/bgarch/public_html/header.html"); ?>
</div>

<div class="clear"></div>

<div class="displaywrapper">
    <?php include_once("content.html"); ?>
</div></div>    

<div class="clear"></div>

<?php include_once("/home/bgarch/public_html/footer.html"); ?>

In the second line where the above reads: "../culture/.." the word culture is the variable and is different based on the folder it is in.

What I need to do know is do a "Find/Replace all in project" that automatically replaces all the text inside each 'index.php' file with the following"

<?php include_once("http://www.bgarchitect.co.nz/subPage/index.php"); ?>

I have spent the past 2 hours trying to figure out regular expressions to acomplish this but have been unsuccessful so far.
Maybe it is not possible to do so?

Anyway, I thought I'd ask a question here in hopes it is in fact much easier than I anticipated. So any help/pointer/hints or tricks are much appreciated.

Thanks for reading,
Jannis

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

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

发布评论

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

评论(1

∞觅青森が 2024-07-22 01:37:09

如果我理解正确的话,您想用“子页面”一词替换“文化”一词(即当前目录)吗?

您可以借助 TextMate 捆绑包来完成此操作。

捆绑包 > 捆绑编辑器> 编辑命令,然后添加新命令
将其添加为命令。 我认为它可以满足你的要求。 您必须将命令的输入设置为整个文档,并将输出设置为替换文档

#!/bin/bash

sed "s/"${TM_DIRECTORY##*/}"/theWordYouWanToReplaceTheDirWith/g" | cat

If I understood right, you want to replace the word culture (which is the current directory) with the word subPage?

You can do this with the help of TextMate bundles.

Bundles > Bundle editor > Edit commands, than add a New command.
Add this as a command. I think it does what you want. You have to set the input to the command as Entire document and the output to Replace document.

#!/bin/bash

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