使用正则表达式更新文本文件(Using regex to update a text file)
我在Mac上,刚刚开始学习使用正则表达式。 我在纯文本文件中保留了很多注释,并且这些注释中包含了主题标签(例如,#tag)。 我试图找出如何运行正则表达式来查找我的纯文本文件集合中的所有不同主题标签,并将列表输出到文本文件,然后我可以将其用作我的笔记的目录。
从这里阅读答案,我很确定正则表达式是使用正确的技术来尝试使这项工作,但我缺乏技术词汇来理解可能为我的用例重新组织的类似问题。
我真的很感激被指向正确的方向,一旦我理解了我想要问的问题,我就不怕为自己做一些工作。
I'm on a mac and have just started to learn about using regex. I keep a lot of notes in plain text files, and these have hashtags in them (e.g., #tag ). I'm trying to figure out how I can run a regex to find all the different hashtags in my collection of plain text files, and output the list to a text file that I can then use as a directory for my notes.
From reading answers here I'm fairly sure that regex is the right technology to be using to try to make this work, but I lack the technical vocabulary to make sense of similar questions that might be retooled for my usecase.
I really appreciate being pointed in the right direction, and I'm not afraid of doing some work for myself once I understand the questions I'm trying to ask.
原文:https://stackoverflow.com/questions/24089625
最满意答案
你需要什么,应该开箱即用。 我创建了一个plunker ,显示了你的需求。 有这三种样本状态
$stateProvider .state('home', { url: '/home', template: '<div>home</div>', }) .state('search', { url: '/search', template: '<div>search</div>', }) .state('index', { url: '/index', template: '<div>index</div>', })
这个(与问题相同)条件DISABLES从HOME导航到SEARCH:
$rootScope.$on('$stateChangeStart', function(event, toState , toParams , fromState, fromParams) { var isFromHome = fromState.name =='home' ; var isToSearch = toState.name == 'search'; if(isFromHome && isToSearch) { event.preventDefault(); } });
What you require, should be working out of the box. I created a plunker, showing your requirement in action. There are these three sample states
$stateProvider .state('home', { url: '/home', template: '<div>home</div>', }) .state('search', { url: '/search', template: '<div>search</div>', }) .state('index', { url: '/index', template: '<div>index</div>', })
And this (the same as in question) condition DISABLES navigation from HOME to SEARCH:
$rootScope.$on('$stateChangeStart', function(event, toState , toParams , fromState, fromParams) { var isFromHome = fromState.name =='home' ; var isToSearch = toState.name == 'search'; if(isFromHome && isToSearch) { event.preventDefault(); } });
Check it here
相关问答
更多-
这个代码解决了这个问题,至少在IE和Firefox(没有测试任何其他的,但如果问题甚至存在于其他浏览器,我给它一个合理的工作机会)。 // Prevent the backspace key from navigating back. $(document).unbind('keydown').bind('keydown', function (event) { if (event.keyCode === 8) { var doPrevent = true; var ...
-
使用onunload仅允许您显示消息,但它不会中断导航(因为太晚了)。 但是,您可以使用onbeforeunload ,它会中断导航: window.onbeforeunload = function() { return "Are you sure you want to navigate away?"; } 编辑 :在return语句中删除confirm() ,因为这样会导致预期的确认窗口,而且还显示第一次确认结果的第二个确认。 Using onunload only allows you to ...
-
如果它在控制器内,那么你可以简单地spyOn($ scope,'$ on'); 这是一个简单的例子: angular.module('app', []); angular .module('app') .controller('Example', function ($scope) { $scope.$on('event', (event, args) => { $scope.args = args; event.stopPropagation(); ...
-
在作者#show Controller中,你可以写例如 - Authors#Show def show @author = Author.find(params[:id]) redirect_to root_url unless @author.display end 在这种情况下,当用户访问任何作者的网址时,它将检查该作者的显示属性是否为真,并相应地重定向。 in the Authors#show Controller, you can write for example -- Authors#Sh ...
-
在keydown事件处理程序中使用e.preventDefault()。 Use e.preventDefault() in the keydown event handler.
-
你需要什么,应该开箱即用。 我创建了一个plunker ,显示了你的需求。 有这三种样本状态 $stateProvider .state('home', { url: '/home', template: 'home', }) .state('search', { url: '/search', template: 'search', }) .state ...
-
Wordpress:阻止导航到内容文件夹中的文件,除非已登录(Wordpress: prevent navigating to files in content folder unless logged in)[2022-03-22]
加 Options All -Indexes 到#END WordPress行后的.htaccess文件。 如果他们尝试,它将阻止人们浏览您的文件夹并显示禁止的消息。 看到: http://catrabbit.com.au/wp-content/uploads/2010/10/ 我误解了这个问题。 抱歉。 澄清: 这会阻止所有人 (登录或以其他方式)浏览您的文件夹。 我不确定为什么要首先允许登录用户浏览uploads文件夹... Found a plugin to handle this: http:// ... -
您应该检查更高的状态而不是每个状态更改,所以如果您有/ login,/ secured,/ secured / ....等路由,则对/ secured状态的resolve子句进行检查,否则您的逻辑将在每次状态更改时执行,这不是身份验证/授权过程的正确方法。 https://github.com/angular-ui/ui-router/wiki 。 这样,您只能在子路径上进行一次检查。 You should make your check on the higher state and not on eve ...
-
最佳做法是在每个路由(配置时)指定是否需要登录, .state("users", { url: "/users", data: { requiresLogin: true } }) 那么你将能够检查状态是否需要在每个导航上登录,如下所示: $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams, options) => { if(toState.data ...
-
您可以从“resource.requested”事件中止任何网络请求。 如果您知道iframe网址,则可以应用此网址。 You can abort any network request from the "resource.requested" event. If you know the iframe URL, then this can be applied.