Start with a cell phone number-Regular expressions

Source: Internet
Author: User

If the picture is dead, please visit: HTTP://WWW.JIANSHU.COM/P/D989CF2453DD
A regular expression is a pattern that describes a set of string characteristics that are used to match a particular string.
–ken Thompson

Although a bit of a show, but I think we have a vague understanding.

The tools you should have

In order to visually see your right and wrong, please use the website online regular test

The stupidest "match."

My last mobile phone number is 18615654686, of course, as the people of the kingdom, there is a +86, this everyone has seen, now assume a scene:
My phone was quoted by a 20 million-word electronic novel, and now I need you to help me find out where to cite it?
Resolution: You will say, use the search, then enter my phone, the results will naturally come out.
It's so smart!

So let's test our matching process with this online tool, copy the following into the text box below the test tool.

5678456ghju124iewlfjds;fei Rice eieiffds,quentin is so handsome!iof+86 18615654686JEWJFEJF

Yes, this is the result of my rolling out on the keyboard, what? I'm so handsome?
Then please enter in the above text box, to match (now ignore +86, directly search my phone number):
First enter 1 , what do you see?

Yes, all of the following text is 1 highlighted. This is what it means: Find all the text that fits 1 this pattern.

Continue typing until you have finished typing my phone, and now you see just my phone is highlighted.
Well, you've done what I need.

The demand has changed.

As a developer, will your leader leave you alone? No!
Now I ask: Find out 20 million of the text inside all the phones, not only my, but also a B-butyl ... Then they call I don't know, but all know is mobile phone number.

Now, the drawbacks of the traditional way of direct search have come out.
Our protagonist-the regular expression comes out. I'll give you a test text, please paste it into the box below the URL again.

Oinehkjfae;jipwohljewrpijlfdslnadasjlfjew;hjkuifewjoioufjsghfslfjdsljfdsljfiesl;fes; Hgslgroigjfojfowefpewfkdlsflwfemnfsjldsljfapoepglkwgnsljflskfjjwio13165115639dsfjiejd;asfk;afje;nv;sajfds; Ajf18677346767mdsfaekwmfksdmal;fmds;afejnwanfsalfdslk18515651188dsjf;awfjl;jsa;fjdaioejai13165789098js; Fkds ' Afje;wjadfs;fk;dsafjew;fds;afjaw;jidsakldjasf;ldjsafnd;safjkeal;fjdsa;lfjweif;fai;jfiw;afjadl;sjfadls; fjnds;ang;ljggf[aofeo[pfjeoif15949860766

OK, now please type in the text box above the test tool \d{9,} ,
OK, you can see that all the phones are out! (Of course, I have a number of phone calls, complex techniques we will discuss later)

Let's explain the above expression:
\dRepresentation number (digital)
{}indicating the number of occurrences, for example, a{3} a appears 3 times, a{3,5} indicating a appears 3 to 5 times, can match, aaa aaaa and aaaaa these three results
That's like my formula, where the numbers appear 9 to N times.

Well, this is a little phone call out of the regular content, you can see the strong and wide application of the regular.
More content, discussed later

Start with a cell phone number-Regular expressions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.