Training: Regex (Training, Regex)

Training: Regex (Training, Regex)

题目描述
Your objective in this challenge is to learn the regex syntax.
Regular Expressions are a powerful tool in your way to master programming, so you should be able to solve this challenge, at least!
The solution to every task is always the shortest regular expression pattern possible.
Also note that you have to submit delimiters in the patterns too. Example pattern: /joe/i. The delimiter has to be /

您在这个挑战中的目标是学习regex语法。
正则表达式是掌握编程的强大工具,所以至少应该能够解决这个挑战!
每个任务的解决方案总是尽可能最短的正则表达式模式。
另请注意,您还必须在模式中提交分隔符。示例模式:/joe/i。分隔符必须是/。

解:

Regex Training Challenge (Level 1)

Your first lesson is easy: submit the regular expression the matches an empty string, and only an empty string.

您的第一课很简单:提交与空字符串匹配的正则表达式,并且只匹配空字符串。

如题正则表达式(百度百科链接:正则表达式
在这里插入图片描述
看看题目要求:提交与空字符串匹配的正则表达式,并且只匹配空字符串。
在这里插入图片描述
空字符的话中间什么都不要吧!注意提交的分隔符! 提交格式:/^$/

Regex Training Challenge (Level 2)

在这里插入图片描述

题目
Easy enough. Your next task is to submit a regular expression that matches only the string ‘wechall’ without quotes.

够简单了。您的下一个任务是提交一个只匹配不带引号的字符串“wechall”的正则表达式。

不带引号的字符串“wechall”,就匹配wechall呗。匹配空字符中间什么都不要,同理,添加wechall。提交格式:/^wechall$/

Regex Training Challenge (Level 3)

在这里插入图片描述

题目
Ok, matching static strings is not the main goal of regular expressions.
Your next task is to submit an expression that matches valid filenames for certain images.
Your pattern shall match all images with the name wechall.ext or wechall4.ext and a valid image extension.
Valid image extensions are .jpg, .gif, .tiff, .bmp and .png.
Here are some examples for valid filenames: wechall4.tiff, wechall.png, wechall4.jpg, wechall.bmp

好吧,匹配静态字符串不是正则表达式的主要目标。
您的下一个任务是提交与某些图像的有效文件名匹配的表达式。
您的模式应匹配名称为wechall.ext或wechall4.ext的所有图像以及有效的图像扩展名。
有效的图像扩展名为.jpg、.gif、.tiff、.bmp和.png。
下面是一些有效文件名的示例:wechall4.tiff、wechall.png、wechall4.jpg、wechall.bmp

注意匹配名称有:wechall.ext,wechall4.ext,wechall4.tiff、wechall.png、wechall4.jpg、wechall.bmp(目前已知的字符串)。先看前缀,不止有wechall,还有wechall4
在这里插入图片描述
前缀不难解决,然后就是后缀了,有效的图像扩展名为:.jpg、.gif、.tiff、.bmp和.png。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
将全部后缀都(或)起来,与 “.” 起来。
在这里插入图片描述
看看自己能不能理解:/^wechall4?\.(?:jpg|gif|tiff|bmp|png)$/(还是自己完成成就感高)

Regex Training Challenge (Level 4)

在这里插入图片描述

题目
It is nice that we have valid images now, but could you please capture the filename, without extension, too?
As an example: wechall4.jpg should capture/return wechall4 in your pattern now.

现在我们有了有效的图像是很好的,但是你能不能捕获文件名,不带扩展名?
例如:wechall4.jpg现在应该在您的模式中捕获/返回wechall4。

在这里插入图片描述

应该能理解吧:/^(wechall4?)\.(?:jpg|gif|tiff|bmp|png)$/(还是自己完成成就感高)

wechall相关链接:我的wechall之旅??!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值