Koj tuaj yeem ua dab tsi nrog regex?
Koj tuaj yeem ua dab tsi nrog regex?

Video: Koj tuaj yeem ua dab tsi nrog regex?

Video: Koj tuaj yeem ua dab tsi nrog regex?
Video: Splitting a PDF to Multiple PDFs with Python! 2024, Kaum ib hlis
Anonim

Cov lus qhia tsis tu ncua yog siv nyob rau hauv kev tshawb fawb xyaw, nrhiav thiab hloov dialogs ntawm lo lus processors thiab cov ntawv nyeem editors, nyob rau hauv cov ntawv nyeem utilities xws li sed thiab AWK thiab nyob rau hauv lexical tsom xam. Muaj ntau hom lus programming muab regex ua muaj peev xwm yog built-in lossis los ntawm cov tsev qiv ntawv.

Tib neeg kuj nug, dab tsi regex siv tau?

A kev qhia tsis tu ncua yog ib ntu ntawm cov cim siv rau parsing thiab manipulating hlua. Lawv feem ntau siv rau ua kev tshawb fawb, hloov substrings thiab validate cov ntaub ntawv. Cov kab lus no muab cov lus qhia, kev ua kom yuam kev, cov peev txheej thiab cov kauj ruam rau kev mus dhau qhov nyuaj cov lus qhia tsis tu ncua.

Tsis tas li ntawd, koj ua li cas hauv regex? Rau sib tw tus cwj pwm muaj lub ntsiab lus tshwj xeeb hauv regex ua , koj yuav tsum siv qhov kev khiav tawm ua ntej nrog lub backslash (). Piv txwv li,. kev sib tw "."; regex ua + kev sib tw "+"; thiab regex ua ( kev sib tw "(". Koj kuj yuav tsum siv regex ua / rau sib tw "" (rov qab-slash).

Ua kom pom qhov no, txhais li cas hauv regex?

Cov lus qhia tsis tu ncua (ua luv luv li " regex ua ") yog cov hlua tshwj xeeb uas sawv cev rau tus qauv uas yuav tsum tau sib phim hauv kev tshawb nrhiav haujlwm. Piv txwv li, hauv a kev qhia tsis tu ncua lub metacharacter ^ txhais tau tias "tsis". Yog li, thaum "a" txhais tau tias "match lowcase a", "^a" txhais tau tias " ua tsis phim tus lej a".

Yuav ua li cas yog ib txwm qhia nrog piv txwv?

Ib qho piv txwv yooj yim rau kev qhia tsis tu ncua yog ib txoj hlua (literal). Piv txwv li, nyob zoo ntiaj teb regex kev sib tw txoj hlua "Hello World".. (dot) yog lwm qhov piv txwv rau kev qhia tsis tu ncua. Ib dot kev sib tw ib tug cim; nws yuav phim, piv txwv li, "a" lossis "1".

Pom zoo: