我正在尝试编写一个regexp来删除链接和图像中的文件路径。
href="path/path/file" to href="file"
href="/file" to href="file"
src="/path/file" to src="file"
and so on...
我认为我已经让它工作了,但是如果它正在处理的字符串中有两个路径,它就会搞乱。我觉得我的表情太贪婪了。它查找整个字符串中的最后一个文件。
这是我的代码,它显示了测试输入上的表达式:
<script type="
我试图使用Javascript以这种方式选择:!something: somethingelse; --感叹号、冒号和分号--必须存在,但其他部分可以是任何值。我试过这样做:
"!test: value; random text here !another: valueagain;".match(/!(.*):(.*);/g);
这将返回原始字符串!test: value; random text here !another: valueagain;。是我做错了什么,还是Regex做错了?
我正在将一些.txt格式的旧wiki文本转换为Markdown (.md)
我在txt文本中有一些javascript示例,并希望正确地包装它们,因此我使用:/(<code javascript\>([\s\S]*)<\/code\>)/来匹配这些部分。
这个大霸王仍然漏掉了一些部件。下面是这个问题的一个例子:
var text = 'This is a text to test:<code javascript>var x = {foo: bar}; alert(JSON.stringify(x));</code>Then any st
在我熟悉的所有语言的正则表达式引擎中,.*表示法表示匹配零或多个字符。考虑以下Javascript代码:
var s = "baaabcccb";
var pattern = new RegExp("b.*b");
var match = pattern.exec(s);
if (match) alert(match);
这输出baaabcccb
Python也会发生同样的情况:
>>> import re
>>> s = "baaabcccb"
>>> m = re.search("
我想获得一个js文件的内容注释。我试着用代码
import re
code = """
/*
This is a comment.
*/
/*
This is another comment.
*/
"""
reg = re.compile("/\*(?P<contents>.*)\*/", re.DOTALL)
matches = reg.search(code)
if matches:
print matches.group("contents")
我得到的结果是
This is a
我有以下正则表达式:
Defaults(.*)Class=\"(?<class>.*)\"(.*)StorePath=\"(?<storePath>.*)\"
和下面的字符串:
Defaults Class="Class name here" StorePath="Any store path here" SqlTable="SqlTableName"
我正在努力实现以下目标:
class Class name here
storePath Any store path here
但我得到的
我有一个很长的文本,其中包含一些文件的路径。
我想要做的是移除它的路径。这些电影都是这样的:
some text 1
/all/extraItems/Java/.Scripts/.Sample1.js
some text 2
/all/extraItems/Android/.Scripts/.Sample2.js
some text 3
我知道,使用"^/all"将选择一个以/all开头的句子,以及以.js结尾的.js$。但我不能把它们合并在一起来选择整个文件。
毕竟,正则表达式应该放在下面的代码中,以移除路径。
text.replaceAll(<RegularExpre
我在尝试捕获字符串上的组时遇到问题:
"type=gist\nYou need to gist this though\nbecause its awesome\nright now\n</code></p>\n\n<script src=\"https://gist.github.com/3931634.js\"> </script>\n\n\n<p><code>Not code</code></p>\n"
我的正则表达式当前如下所示:
/<code>(
我想要找到在字符串中括在括号中的本地化文本,该字符串看起来类似。
{{de:German}{en:English}}, {{de:German2}{en:English2}}
因此,对于上面的例子,我希望找到两个!本地化字符串。
我使用以下正则表达式。
\{\{.+\}\}
结果,我只找到了一个文本匹配,而没有找到预期的两个匹配。我在这里做错了什么?
预期比赛:
First match -> {{de:German}{en:English}}
Second match -> {{de:German2}{en:English2}}
谢谢你的帮忙