首页 \ 问答 \ Python正则表达式(Python regular expression)

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 the str2 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
更新时间:2023-04-27 10:04

最满意答案

从特定类的原型获取特定函数并调用它设置当前上下文( 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 ...
  • 从特定类的原型获取特定函数并调用它设置当前上下文( 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) ...
  • 这是一个一旦设置就无法更改的变量。 当你拥有多线程代码时非常有用,因为能够更改变量的值可能会成为代码中许多难以找到问题的根源。 如果它是不可变的,那通常很好。 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 ...
  • 全局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 ...
  • 您只能在声明它的方法中引用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 ...
  • ...并且手动扩展参考似乎是完全错误的方向。 这比那更糟糕。 根据API : 由于引用对象是与垃圾收集器密切配合实现的,因此该类可能不会直接进行子类化。 如果你希望能够在同一个结构中存储多种不同类型的引用,包括strong,那么最好的办法就是创建自己的引用接口并进行两种实现:一个包装一个Reference ,一个包装一个正常的目的。 ...and extending Reference manually seems like the completely wrong direction. It's w ...
  • 据我了解,你一般不会询问PHP引用,而是关于$foo =& new Bar(); 建筑成语。 这只能在PHP4中看到,因为通常的$foo = new Bar()存储对象的副本 。 除非类在构造函数中存储对$ this的引用,否则通常不会引起注意。 稍后在返回的对象上调用方法时,当意图可能只有一个时,将存在两个不同的对象副本。 考虑这个代码,其中构造函数在全局变量中存储对$ this的引用 class Bar { function Bar(){ $GLOBALS['copy']=&$th ...
  • 如果使用&$foo通过引用显式传递变量,则只通过引用(在当前版本的PHP中)传递变量。 同样,在将变量声明为新变量(例如$foo = $bar ,$ foo将是对$ bar的引用,直到值发生变化。 然后它是一个新的副本。 这里有很多检测参考的方法,也许可以检查一些参考 。 (为什么你需要这样做是未知的,但它仍然存在)。 http://www.php.net/manual/en/language.references.spot.php A variable is only passed by referenc ...
  • fu返回char* ,但是您使用它来初始化对不同类型的string的引用。 这可以通过创建一个临时string来解决,该string包含指针引用的字符串副本,并使用该临时字符串初始化引用。 更改lol[0]不会影响该字符串。 如果你想引用指针lol[0] ,那么fu必须返回一个引用,而ru必须是对正确类型的引用: char *& fu(int i){return lol[i];} char *& ru = fu(0); (顺便说一句,你应该使用const char *指向字符串文字,因为它们是常量。由于 ...
  • 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 => ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)