64 lines
1.4 KiB
Markdown
64 lines
1.4 KiB
Markdown
|
---
|
||
|
title: 提取路径
|
||
|
updated: 2022-03-14 07:47:18Z
|
||
|
created: 2022-01-10 03:35:59Z
|
||
|
tags:
|
||
|
- aardio
|
||
|
- cadence
|
||
|
- 代码块
|
||
|
- 数据筛选
|
||
|
---
|
||
|
|
||
|
cadence的用户配置文件env中路径信息格式有些特殊。
|
||
|
键值中各路径信息之间用空格` `分隔,路径信息中存在空格的,此路径信息放于`""`对之间,如
|
||
|
|
||
|
```
|
||
|
set psmpath = $psmpath E:\lib\psm\
|
||
|
set padpath = $padpath E:\lib\pad\
|
||
|
set viewpath = $viewpath "E:\usercfg\test path\"
|
||
|
```
|
||
|
透过现象看本质是选择算法的重要前提,不可先入为主,不可被表象误导。
|
||
|
|
||
|
**此需求的本质**,是从字符串中提取两种东西:
|
||
|
1. 不含空格或引号的字符序列;
|
||
|
1. 以引号开头和结尾的字符序列
|
||
|
|
||
|
故可采用以下方法:
|
||
|
> 若没有混排则可直接调用`string.split`进行分割
|
||
|
```
|
||
|
import console;
|
||
|
var str = /*************
|
||
|
$viewpath "E:\usercfg\test path\" E:\lib\pad\ "E:\usercfg\test path 2\" $viewpath2
|
||
|
*************/
|
||
|
|
||
|
import preg
|
||
|
var pattern = //[^\s"]+|"[^"]*"
|
||
|
var regex = preg(pattern)
|
||
|
var res= {}
|
||
|
for m in regex.gmatch( str) {
|
||
|
table.push(res,m)
|
||
|
}
|
||
|
console.dump(res)
|
||
|
|
||
|
console.pause(true);
|
||
|
```
|
||
|
结果为
|
||
|
```
|
||
|
{
|
||
|
[1]="$viewpath";
|
||
|
[2]='"E:\\usercfg\\test path\\"';
|
||
|
[3]="E:\lib\pad\";
|
||
|
[4]='"E:\\usercfg\\test path 2\\"';
|
||
|
[5]="$viewpath2"
|
||
|
}
|
||
|
请按任意键继续 ...
|
||
|
```
|
||
|
提取所有键对的程序见
|
||
|
|
||
|
|
||
|
[提取路径.aardio](../_resources/提取路径_提取路径.aardio)
|
||
|
|
||
|
#aardio
|
||
|
#cadence
|
||
|
#代码块
|
||
|
#数据筛选
|