返回

正则表达式教程:迅雷链接校验

正则表达式

一、正则解释

该正则表达式的语法如下:

  • ^: 匹配字符串的开头。
  • thunderx?: 匹配可选的 "thunder" 或 "thunderx" 前缀。
  • :\/\/: 匹配冒号和两个斜杠。
  • [a-zA-Z\d]+: 匹配一个或多个字母或数字。
  • =$: 匹配字符串的结尾。

二、使用场景

该正则表达式可用于验证文本中是否包含有效的迅雷链接。它可以用于各种应用程序,例如:

  • 下载管理器
  • 文件共享网站
  • 批量链接验证工具

三、代码示例

JavaScript

const regex = /^thunderx?:\/\/[a-zA-Z\d]+=$/;

const text = "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo=";

console.log(regex.test(text)); // true

Java

import java.util.regex.Pattern;

public class RegexTest {

    public static void main(String[] args) {
        Pattern pattern = Pattern.compile("^thunderx?:\/\/[a-zA-Z\d]+=
import java.util.regex.Pattern;

public class RegexTest {

    public static void main(String[] args) {
        Pattern pattern = Pattern.compile("^thunderx?:\/\/[a-zA-Z\d]+=$");

        String text = "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo=";

        boolean matches = pattern.matcher(text).matches();

        System.out.println(matches); // true
    }
}
quot;
); String text = "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo="; boolean matches = pattern.matcher(text).matches(); System.out.println(matches); // true } }

PHP

$pattern = "/^thunderx?:\/\/[a-zA-Z\d]+=$/";

$text = "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo=";

preg_match($pattern, $text, $matches);

var_dump($matches); // array(1) { [0] => "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo=" }

Python

import re

pattern = r"^thunderx?:\/\/[a-zA-Z\d]+=
import re

pattern = r"^thunderx?:\/\/[a-zA-Z\d]+=$"

text = "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo="

result = re.match(pattern, text)

print(result.group(0)) # "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo="
quot;
text = "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo=" result = re.match(pattern, text) print(result.group(0)) # "thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo="