Python:用正则表达式捕获双反斜杠C char

时间:2016-01-15 20:53:53

标签: python c regex backslash

我试图通过re模块使用Python正则表达式捕获 Customer ted = new Customer(); ted.FirstName = "Ted"; ted.LastName = "Smith"; //this will give you "blue" var color = ted.Color; 。我尝试使用以下方法执行此操作:

'\\'

back = re.compile(r"'\\'") print back.findall(line) 的位置:line

但这并没有抓住任何东西。

我也尝试过:

char = '\\';

无济于事。我的正则表达式有什么问题?

1 个答案:

答案 0 :(得分:5)

你需要逃避反斜杠:

>>> back = re.compile(r"'\\\\'")
>>> line = r"char = '\\';"
>>> print back.findall(line)
["'\\\\'"]

<强>代码:

<div class="item item-divider" ng-style="scoreColor"><b>Rate</b>&nbsp;{{score}}</div>
<input type="range" name="rate" min="1" max="10" value="5" step="1" ng-model="score" ng-change="changeScoreColor(score)"/> 

$scope.changeScoreColor = function(score){
    $scope.scoreColor = "{background-color:" + colorFromScore(score) + ";}";
};



TypeError: name.replace is not a function
    at camelCase (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11098:5)
    at forEach.css (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11541:12)
    at Object.JQLite.(anonymous function) [as css] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11667:9)
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:33610:57
    at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9022:20)
    at ngStyleWatchAction (http://localhost:8100/lib/ionic/js/ionic.bundle.js:33610:7)
    at Object.$watchCollectionAction [as fn] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22809:13)
    at Scope.$digest (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22942:29)
    at Scope.$apply (http://localhost:8100/lib/ionic/js/ionic.bundle.js:23205:24)
    at $$debounceViewValueCommit (http://localhost:8100/lib/ionic/js/ionic.bundle.js:31961:14)