Python正则表达式(Python regular expression)
我有两种类型的字符串
str1 = "{#decode(en.flower)}" str2 = "{#en.flower}"
我想通过正则表达式捕获这两种类型的字符串,但我无法捕获
str1
字符串。 捕获str2
字符串不成问题。我的正则表达式是
r'\{\#([a-zA-Z]\()?(en|kr)\.[a-zA-Z0-9_]+[\)]?\}'
为什么我不能捕获字符串?
I have two types of strings
str1 = "{#decode(en.flower)}" str2 = "{#en.flower}"
I want to capture both of these types of strings by a regular expression, but I can't capture the
str1
string. Capturing thestr2
string is no problem.My Regular expression is
r'\{\#([a-zA-Z]\()?(en|kr)\.[a-zA-Z0-9_]+[\)]?\}'
Why can't I capture the
str
string?
原文:https://stackoverflow.com/questions/30592194
最满意答案
从特定类的原型获取特定函数并调用它设置当前上下文(
this
):A.prototype.foo.call(this)
虽然请注意我会建议这在PHP和Javascript中都是一个坏主意。 只是让覆盖工作正常,这就是它被覆盖的东西。
Get the specific function from the specific class' prototype and call it setting the current context (
this
):A.prototype.foo.call(this)
Though note that I would suggest this is a bad idea, both in PHP and Javascript. Just let the override work its course, that's what it's overridden for.
相关问答
更多-
使用函数ref : $ref_type = ref $ref; 返回值是: SCALAR , ARRAY , HASH , CODE (引用子程序), GLOB (引用typeglob )和REF (引用引用)中的一个。 实际上, ref函数可能返回更多的值,并且在引用对象的情况下返回包名而不是类型: http : //perldoc.perl.org/functions/ref.html 。 Use function ref: $ref_type = ref $ref; The return valu ...
-
如何获得自习班的参考?(How to get reference of self class?)[2022-01-28]
从特定类的原型获取特定函数并调用它设置当前上下文( this ): A.prototype.foo.call(this) 虽然请注意我会建议这在PHP和Javascript中都是一个坏主意。 只是让覆盖工作正常,这就是它被覆盖的东西。 Get the specific function from the specific class' prototype and call it setting the current context (this): A.prototype.foo.call(this) ... -
什么是不变的参考?(what is an immutable reference?)[2022-03-18]
这是一个一旦设置就无法更改的变量。 当你拥有多线程代码时非常有用,因为能够更改变量的值可能会成为代码中许多难以找到问题的根源。 如果它是不可变的,那通常很好。 It's a variable that cannot be changed once set. Very useful when you have multithreaded code since being able to change a variable's value might be a source of many hard to fi ... -
什么是作业与参考?(What is assignment vs reference?)[2022-08-13]
全局vs本地的关键问题是名称是否由赋值语句绑定。 x = 1 #assignment y = x + 1 #reference 是对的。 x[0] = 1 #reference or assignment???? 这是对x的引用。 此语句与x.__setitem__(0, 1)效果相同。 它在x上调用一个方法。 它不分配给名称x 。 x += 1 #reference or assignment???? 这是对x的赋值。 它与x = x.__iadd__(1)具有相同的效果。 The key ques ... -
如何参考本地课程(How to reference local class)[2023-11-26]
您只能在声明它的方法中引用Local Inner类: public void wrapper() { class Local { } Local obj = new Local(); } 由于范围有限,这些类往往不是很有用。 如果您找到了一个有效的用例来定义一个,请看一下本教程 。 You can only reference a Local Inner class inside the method in which you have declared it: public void wr ... -
强参考课程(Strong Reference class)[2022-01-06]
...并且手动扩展参考似乎是完全错误的方向。 这比那更糟糕。 根据API : 由于引用对象是与垃圾收集器密切配合实现的,因此该类可能不会直接进行子类化。 如果你希望能够在同一个结构中存储多种不同类型的引用,包括strong,那么最好的办法就是创建自己的引用接口并进行两种实现:一个包装一个Reference,一个包装一个正常的目的。 ...and extending Reference manually seems like the completely wrong direction. It's w ... -
Php通过参考(Php By Reference)[2023-01-07]
据我了解,你一般不会询问PHP引用,而是关于$foo =& new Bar(); 建筑成语。 这只能在PHP4中看到,因为通常的$foo = new Bar()存储对象的副本 。 除非类在构造函数中存储对$ this的引用,否则通常不会引起注意。 稍后在返回的对象上调用方法时,当意图可能只有一个时,将存在两个不同的对象副本。 考虑这个代码,其中构造函数在全局变量中存储对$ this的引用 class Bar { function Bar(){ $GLOBALS['copy']=&$th ... -
参考或变量?(Reference or variable?)[2020-02-03]
如果使用&$foo通过引用显式传递变量,则只通过引用(在当前版本的PHP中)传递变量。 同样,在将变量声明为新变量(例如$foo = $bar ,$ foo将是对$ bar的引用,直到值发生变化。 然后它是一个新的副本。 这里有很多检测参考的方法,也许可以检查一些参考 。 (为什么你需要这样做是未知的,但它仍然存在)。 http://www.php.net/manual/en/language.references.spot.php A variable is only passed by referenc ... -
本地参考不参考(local reference does not reference)[2022-10-18]
fu返回char* ,但是您使用它来初始化对不同类型的string的引用。 这可以通过创建一个临时string来解决,该string包含指针引用的字符串副本,并使用该临时字符串初始化引用。 更改lol[0]不会影响该字符串。 如果你想引用指针lol[0] ,那么fu必须返回一个引用,而ru必须是对正确类型的引用: char *& fu(int i){return lol[i];} char *& ru = fu(0); (顺便说一句,你应该使用const char *指向字符串文字,因为它们是常量。由于 ... -
通过价值和参考(Pass By Value & Reference)[2022-12-15]
a永远不会在过程之外更改,因为它是通过值传递的,而b将被更改,因为它是通过引用传递的。 通过引用传递的变量的赋值将保留在过程之外。 查看它的一种方法是用调用者变量替换引用参数,用b代替y,z。 而不能替代a,因为它是按价值调用的。 现在你的代码看起来像这样,如果w,x通过引用传递值y,z通过引用:a将是5不变,而b将是: int a <-- 5 int b <-- 6 w <-- a + 1 x <-- a * 2 b <-- b + 3 => b will be 9 b <-- b * 4 => ...