我需要循环遍历匹配查询的所有文件并显示文件名。
目前我只能让它对所有文件都有效。
for filename in ~/notes/*
do
NAME=`basename "$filename"`
echo ${NAME%.*}
done;
这将删除完整路径和文件扩展,并回显文件名。
我需要同样的东西,但对于文件名中有我的查询的文件。我试过了,什么都不回
for filename in ~/notes/\*$*\*
do
TEST=`basename "$filename"`
echo ${TEST%.*}
done;
如果我echo $
我想删除文件名的最后三个字符。要重命名任何文件,我将使用:
String str = ""; // Here set File name, i.e. listFile.getName();
String[] tempFile = str.split("[$^txt]");
这个regex删除最后三个字符是可以的,但是当传递包含"t OR x“的任何文件名时,regex会删除它。例如:
1) fileName.txt -> result after split -> fileName -> OK.
2) textfile.txt
对于一个web应用程序,我正在尝试开发一个javascript,它与.json中没有结尾的内容相匹配。听起来很简单,但我觉得很难。
我首先想要这样做:^.*(?!\.json$),但这显然不起作用,因为它只是匹配整个字符串。然后我尝试了^[^\.]*(?!\.json$),但这与ab在abc.json中的匹配。
我已经想出了两个正则表达式来完成这个任务,但是我希望有一个正则表达式能够做到这一点。
// Match anything that has a dot but does not end in .json
^.*\.(?!json$)
// Match anything that doe
我需要一个regex来获取所有具有.php扩展名的文件,但它不包含.html。
例如:
foo.php (this file is ok)
foo.html.php (this file is not ok)
foo.bar (this file is not ok)
foo.bar.php (this file is ok)
我创建了这个regex:
^(?!.*(.html))
但通过这种方式,我还可以获得以.bar结尾的文件(而不仅仅是.php)。
我刚刚使用Python图像库(PIL)进行了一些图像处理,使用的是我之前找到的对图像执行傅立叶变换的帖子,但我无法使用save函数。整个代码运行良好,但它不会保存生成的图像:
from PIL import Image
import numpy as np
i = Image.open("C:/Users/User/Desktop/mesh.bmp")
i = i.convert("L")
a = np.asarray(i)
b = np.abs(np.fft.rfft2(a))
j = Image.fromarray(b)
j.save("C:/Us
"abc_d1.txt" should get 0
"abc_d1_2.txt" should get 2
"abc_d1_14.txt" should get 14
"abc_d12_x2_156.txt" should get 156
这是我迄今为止所做的,但我没有得到正确的结果。
string y = "tester_yg1.txt";
string pattern = @"(\d+)(?!.*\d)";
Regex rg = new Regex(pattern);
var z