"DEVICE|30ef50097851f4220c95ce4fed365c8f|clStr0:026|clStr1:设备26#|clStr2:注塑车间|clStr3:工位机8#|000";js正则获取|之间的内容
时间: 2023-08-12 22:27:56 浏览: 50
可以使用正则表达式`/\|(.*?)\|/g`来获取字符串中`|`之间的内容。具体代码如下:
```javascript
const str = "DEVICE|30ef50097851f4220c95ce4fed365c8f|clStr0:026|clStr1:设备26#|clStr2:注塑车间|clStr3:工位机8#|000";
const regex = /\|(.*?)\|/g;
const matches = str.matchAll(regex);
const contents = [];
for (const match of matches) {
contents.push(match[1]);
}
console.log(contents); // ["30ef50097851f4220c95ce4fed365c8f", "clStr0:026", "clStr1:设备26#", "clStr2:注塑车间", "clStr3:工位机8#", "000"]
```
其中`contents`数组即为所需的内容。
相关问题
js 正则截取DEVICE|d9f4b2ea55e3beb2603b4ffe18b675a7|clStr1:1号设备|clStr2:生产车间|clStr3:工位机2# 中|之间的内容
可以使用正则表达式来截取,具体的正则表达式如下:
```
/DEVICE\|[^|]+\|([^|]+)\|([^|]+)\|([^|]+)/
```
使用该正则表达式可以匹配 `DEVICE|d9f4b2ea55e3beb2603b4ffe18b675a7|clStr1:1号设备|clStr2:生产车间|clStr3:工位机2#` 这个字符串,然后把 `|` 分隔符中间的内容提取出来,分别对应 `1号设备`、`生产车间`、`工位机2#` 这三个字符串。
具体的 JavaScript 代码如下:
```javascript
const str = 'DEVICE|d9f4b2ea55e3beb2603b4ffe18b675a7|clStr1:1号设备|clStr2:生产车间|clStr3:工位机2#';
const matches = str.match(/DEVICE\|[^|]+\|([^|]+)\|([^|]+)\|([^|]+)/);
const results = matches ? matches.slice(1) : null;
console.log(results);
```
输出结果为:
```
["1号设备", "生产车间", "工位机2#"]
```
if lsusb | grep -q "2c7c:6005"; then ping_moden=EC200A_CAT4 fi
As an AI language model, I cannot determine the context of this code snippet. However, what I can do is to explain what it does in general.
This code checks if the USB device with the vendor ID of "2c7c" and product ID of "6005" is connected to the system using the `lsusb` command. If the device is found, it sets a variable `ping_moden` to "EC200A_CAT4". This variable may be used for further operations.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)