const font_family_Regex=/\(zt:(.*?)\)/; const line = "是谁是谁(zt:楷体)" let alignMatch = line.match(font_family_Regex); if(alignMatch ){ const textAlign = alignMatch[1]; console.log(textAlign ) } else{ console.log(123) }
时间: 2024-03-23 22:42:06 浏览: 23
你的代码看起来是想提取字符串 `line` 中 `(zt:楷体)` 中的 `楷体`,然后将其输出到控制台。
不过你的代码存在一些问题:
1. 正则表达式中的 `font_family_Regex` 变量名与实际的正则表达式不符,应该是 `/\(zt:(.*?)\)/`。
2. 在使用 `match()` 方法匹配字符串时,应该使用 `line.match(font_family_Regex)`,而不是 `font_family_Regex.match(line)`。
3. 在输出 `textAlign` 变量时,应该使用 `console.log(textAlign)`,而不是 `console.log(alignMatch)`。
修改后的代码如下:
```javascript
const font_family_Regex = /\(zt:(.*?)\)/;
const line = "是谁是谁(zt:楷体)";
let alignMatch = line.match(font_family_Regex);
if (alignMatch) {
const textAlign = alignMatch[1];
console.log(textAlign);
} else {
console.log(123);
}
```
输出结果为:
```
楷体
```
相关问题
js 一个 正则验证 下面三个链接 https://live.bilibili.com/9906982?a=1 https://live.bilibili.com/9?b=` https://live.bilibili.com/99?c=A
你可以使用正则表达式来验证这三个链接。以下是一个示例的正则表达式,可以用于验证这些链接是否符合要求:
```javascript
const regex = /^https:\/\/live\.bilibili\.com\/\d+\?[a-zA-Z]=\w+$/;
const link1 = "https://live.bilibili.com/9906982?a=1";
const link2 = "https://live.bilibili.com/9?b=`";
const link3 = "https://live.bilibili.com/99?c=A";
console.log(regex.test(link1)); // true
console.log(regex.test(link2)); // false
console.log(regex.test(link3)); // true
```
这个正则表达式的含义是:以`https://live.bilibili.com/`开头,后面跟着一个或多个数字,然后是`?`,再后面是一个字母(大小写不限),最后是一个或多个字母、数字或下划线。
VUE2获取请求地址http://sso.chac.de/ssologout?redirect_uri=http://10.10.24.80:8088/home中的参数
你可以使用以下代码来获取请求地址中的参数:
```javascript
// 获取 URL 中的参数
function getQueryString(name) {
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
const r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 示例调用
const redirectUri = getQueryString("redirect_uri");
console.log(redirectUri); // http://10.10.24.80:8088/home
```
在上面的代码中,`getQueryString` 函数使用正则表达式来匹配 URL 中的参数,如果找到匹配的参数,则返回该参数的值。你可以将你要获取的参数名作为参数传递给该函数。在示例中,我们通过传递 "redirect_uri" 来获取请求地址中的 "redirect_uri" 参数,并将其赋值给变量 `redirectUri`。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![mhtml](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)