Regular expression confirmation quiz!

at first

Oops! There was no confession of the village on the way, and there was a room with a very quiet progress. So, even though I wasn't bitten by the dictator until the end, I wish I was lonely when the three red-haired people told me that the villages other than myself were wiped out and two wolves were wolf and black would win! !! Crying

Jesse is still a fledgling, but isn't it good for exercises? So I made a regular expression quiz! I'm talking about something confusing, "What? Why ??"

What is a regular expression?

If you don't know what regular expressions are, you should study at the following site first! When I actually use it, I use the module re (in Python), but I'll omit that part and it's a quiz that anyone can think of! Please try it!

--Summary of regular expressions: https://uxmilk.jp/41416 --More details: https://qiita.com/grrrr/items/7c8811b5cf37d700adc4

problem

Character string <a href="/sample/page:1234" rel="last"> If you search from here with the following regular expression, answer where it gets stuck! Exactly from start to finish!

1. r'[0-9]*' 2. r'[0-9]*?' 3. r'[0-9]+' 4. r'[0-9]+?'

Don't see the answer right away

I'll leave some space.

What does ? Mean

It's a little difficult to understand.

See you soon

answer

1. r'[0-9]*' This is ... from the very beginning, it's 0 characters! If you are told that the number is 0 or more, it doesn't matter if there is nothing.

2. r'[0-9]*?' ? It doesn't matter if there is a previous character or not, and it doesn't have to be 0 characters, so it's the same as 1., it's 0 characters from the beginning!

3. r'[0-9]+' This means taking the chunks of numbers as long as possible! 1234 will be chosen!

4. r'[0-9]+?' The difference from the previous one is that + may or may not be present, so it will be 1! With [0-9], one is already reserved, and you won't repeat + with the others!

At the end

I want to correct the first two, "It's unpleasant to say that they match even if nothing happens", and the feeling of 3. as long as possible and the feeling of 4. I want to remember ~. What is the whole principle?

I scraped it with Python, so please check it out! https://qiita.com/Jessica_nao_/items/140b435a9e13054ed78e

I would be happy if a strong person could give me a problem! I'm sorry!

Recommended Posts

Regular expression confirmation quiz!
Regular expression Greedy
Regular expression re
Regular expression in regex.h
Regular expression with pymongo
Date notation regular expression
Regular expression matching method
Regular expression in Python
Regular expression in Python
Python 處 處 regular expression Notes
Julia Quick Note [04] Regular Expression
Decompose hostname with co.jp with regular expression
String replacement with Python regular expression
100 language processing knocks 2020: Chapter 3 (regular expression)
Introduction to regular expression processing system
(Python) HTML reading and regular expression notes
Search pythondict dictionary key by regular expression