Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 中间部分正则表达式_Regex - Fatal编程技术网

Regex 中间部分正则表达式

Regex 中间部分正则表达式,regex,Regex,我打算写一些正则表达式来匹配字符串的开头和结尾 开始: 完: -结束 输入/匹配示例: 输入匹配 https://www.example.com.au/hithere-end Y https://www.example.com.au/hi-there-end Y https://www.example.com.au/hithere-endx N https://www.example.com.au/end N 这就是我到目前为止所做的: ^https?://(w

我打算写一些正则表达式来匹配字符串的开头和结尾

开始:

完:

-结束

输入/匹配示例:

输入匹配
https://www.example.com.au/hithere-end   Y
https://www.example.com.au/hi-there-end  Y
https://www.example.com.au/hithere-endx  N
https://www.example.com.au/end           N

这就是我到目前为止所做的:

^https?://(www\.)?example\.com\.au/[A-z](\-end)$
有什么帮助吗

谢谢。

试试这个模式:

^https?:\/\/(?:www\.)?example\.com\.au\/(.+)-end$
更改您的模式:

  • /
    被转义(使用
    \
    ,3次)
  • 第一个组更改为非捕获组(
    ?:
  • [A-z]
    匹配单个大写字母。更改为
    (.+)
    (a捕获组)
  • 从最后一个组中删除了括号(您不想捕获它),因此也不需要
    \
要捕获的“中间部分”位于组1中。

尝试以下模式:

^https?:\/\/(?:www\.)?example\.com\.au\/(.+)-end$
更改您的模式:

  • /
    被转义(使用
    \
    ,3次)
  • 第一个组更改为非捕获组(
    ?:
  • [A-z]
    匹配单个大写字母。更改为
    (.+)
    (a捕获组)
  • 从最后一个组中删除了括号(您不想捕获它),因此也不需要
    \
要捕获的“中间部分”位于组1中。

请检查以下内容:

^(https?://(www\.)?example\.com\.au/)[A-z]*(-end)$
应该有效。

检查以下内容:

^(https?://(www\.)?example\.com\.au/)[A-z]*(-end)$
应该有用。

试试这个C代码


Somestring.StartsWith(“”)

Somestring.EndsWith(“-end”)

试试这个C代码


Somestring.StartsWith(“”)


Somestring.EndsWith(“-end”)

小心,
[A-z]
匹配的不仅仅是字母(例如,它还匹配
[
以及ASCII
z
A
之间的其他字符)。使用
[A-Za-z]
或使正则表达式不区分大小写,并使用
[A-z]
。小心,
[A-z]
匹配的不仅仅是字母(例如,它还匹配
[
和ASCII
Z
a
之间的其他字符)。使用
[a-Za-Z]
或使正则表达式不区分大小写,并使用
[a-Z]