RightToLeft标志和原子组

时间:2017-02-05 18:31:45

标签: c# regex

当RightToLeft被激活时,为什么a(?>.*)abc不匹配?

我期望它的工作方式是:

  1. 最右侧的字符(c)与a不匹配。
  2. 下一个字符是b。它再次与a不匹配。
  3. a匹配a;原子组中的贪婪.将匹配b和c。没有更多的角色,正则表达式得到满足。

1 个答案:

答案 0 :(得分:2)

问题与RightToLeft选项无关。以相反的顺序搜索字符串,但是需要考虑的其他事情是模式标记也以相反的顺序进行测试。首先是.run(function($ionicPlatform, $rootScope, $state, AuthService) { $ionicPlatform.ready(function(){ AuthService.userIsLoggedIn().then(function(response) { if(response === true) { $state.go('tab.home'); } else { $state.go('auth.login'); } }); // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); cordova.plugins.Keyboard.disableScroll(true); } if (window.StatusBar) { // org.apache.cordova.statusbar required StatusBar.styleDefault(); } }); // UI Router Authentication Check $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams){ if (toState.data.authenticate) { AuthService.userIsLoggedIn().then(function(response) { if(response === false) { event.preventDefault(); $state.go('auth.login'); } }); } }); }) ,然后是<ion-view> <ion-header-bar class="bar-stable"> <h1 class="title">Log In</h1> </ion-header-bar> <ion-content class="padding"> <button class="button button-block button-positive" ng-click="facebookLogin()">Login with Facebook</button> <div class="row"> <div class="col col-center"> <h4 class="text-center">OR</h4> </div> </div> <form name="login_form" class="form-container" novalidate> <div class="list list-inset"> <label class="item item-input"> <input type="email" placeholder="Email" ng-model="user.email" required> </label> <label class="item item-input"> <input type="password" placeholder="Password" ng-model="user.password" required> </label> </div> <button class="button button-block button-balanced" ng-click="login(user)" ng-disabled="login_form.$invalid">Login</button> </form> <button class="button button-block button-clear button-positive button-small" ui-sref="auth.signup"> Sign Up </button> <div ng-show="errors"> <p class="message error" ng-repeat="error in errors"><b>[{{error.code}}]</b> {{error.msg}}</p> </div> </ion-content> </ion-view>

原子团禁止回溯。由于(?>.*)默认是贪婪的,它需要c,然后是b,然后是a(换句话说,它需要“abc”),但由于原子组a不会给回一个字符( a)并且模式将失败。

(请注意,如果没有RightToLeft选项,您将尝试使用模式.*)在“cba”中查找出现的情况

没有RightToLeft选项的更简单的示例,总是使用字符串“abc”,但模式为.*

(?>.*)a

如果这次我使用非捕获组而不是原子组:a(?>.*)c

a         =>   a
a(?>.*)   =>   abc
a(?>.*)c  =>   FAIL since (?>.*) don't give back the c