Yadda Ake Rubutawa da Gyara Matatun Regex don Nazarin Google (Tare da Misalai)

Maganganu na yau da kullun Regex Tacewar Google Analytics

Kamar yadda yake da yawancin labarina a nan, Ina yin bincike don abokin ciniki sannan inyi rubutu game dashi anan. A gaskiya, akwai dalilai guda biyu da yasa… farko shine ina da mummunan ƙwaƙwalwa kuma galibi ina bincike kan gidan yanar gizo na don bayani. Na biyu shine taimakawa wasu wadanda suma suna iya neman bayanai.

Menene Magana ta Yau da kullun (Regex)?

Regex hanya ce ta ci gaba don bincika da gano tsarin haruffa a cikin rubutu don daidaita ko maye gurbin rubutun. Duk harsunan shirye-shiryen zamani suna tallafawa Maganganu na yau da kullun.

Ina son maganganu na yau da kullun (regex) amma suna iya zama ɗan ɗan takaici ko haushi don koyo da gwaji. Nazarin Google yana da wasu iyawa masu ban mamaki… inda zaku iya ƙirƙirar ra'ayoyi tare da maganganu na yau da kullun ko kuma tace bayananku a cikin maganganun yau da kullun.

Misali, idan ina son ganin zirga-zirga a shafukan shafi na, zan iya tace / tag / a cikin tsarin tsari na ta hanyar amfani da:

/tag\/

Aikin gabatarwa yana da mahimmanci a can. Idan kawai nayi amfani da “alama”, zan sami dukkan shafuka tare da alamar kalmar a cikinsu. Idan na yi amfani da “/ tag” to duk URL da ya fara da alama za a haɗa shi, kamar / tag-management saboda Google Analytics tsoho don haɗawa da kowane hali bayan maganganun yau da kullun. Don haka, Ina buƙatar tabbatar da cewa ina da waɗannan yankan da aka haɗa… amma dole ne ya kasance yana da halin tserewa akan sa.

Shafin tace shafi

Abubuwan Asali na Regex

ginin kalma description
^ Farawa da
$ Sare tare da
. Alamar alama ga kowane hali
* Sifili ko fiye na abin da ya gabata
.* Ya dace da kowane haruffa a ciki
? Sifili ko lokaci ɗaya na abin da ya gabata
+ Daya ko fiye da sau na abun da ya gabata
| A OR mai aiki
[abc] A ko b ko c (na iya zama kowane adadi)
[az] Yankin a to z (na iya zama kowane adadi haruffa)
[AZ] Yankin A zuwa Z (babba)
[0-9] Yankin 0 zuwa 9 (na iya zama kowane lamba)
[a-zA-Z] Girman daga zuwa Z ko A zuwa Z
[a-zA-Z0-9] Duk haruffan haruffa
{1} Daidai misalin 1 (na iya zama kowane lamba)
{1-4} Yankin 1 zuwa 4 (na iya zama kowane lamba)
{1,} 1 ko karin lokuta (na iya zama kowane lamba)
() Raba dokokin ku
\ Tserewa haruffa na musamman
\d Halin haruffa
\D Halin da ba na lambobi ba
\s Farin sarari
\S Farar sarari
\w Kalmar
\W Ba kalma (alamar rubutu)

Misalan Regex Don Nazarin Google

Don haka bari mu sanya wasu misalai a waje don wasu Matatun Musamman. Ofaya daga cikin abokan aiki ya nemi taimako don gano shafin ciki tare da hanyar / fihirisa ban da duk rubutun blog waɗanda aka rubuta tare da shekarar a cikin labarin:

Tsarin matata na al'ada don filin Filin Nemi Url:

^/(index|[0-9]{4}\/)

Wannan asalin yana bayyana ne don neman / fira ko OR kowane lambobin adadi 4 wanda yake ƙarewa tare da raguwa mai zuwa. Na ƙirƙiri ra'ayi a cikin Nazarin kuma na ƙara wannan azaman tacewa:

Duba Rarraba Nazarin Google

Ga wasu karin misalai:

  • Kuna da bulogi tare da shekara a cikin hanyar URL permalink kuma kuna son tace jerin zuwa kowace shekara. Don haka ina son kowane adadi na lambobi 4 mai biyo baya. Nemi Tsarin Tacewar URl:

^/[0-9]{4}\/

  • Kuna so ku gwada duk shafukanku inda taken yake takardar shaidar or takardar shaida a ciki. Alamar Tace Tace:

(.*)certificat(.*)

  • Kuna so ku gwada shafuka biyu masu saukowa bisa Matsakaicin Matsayin Kamfen ɗin da aka wuce a cikin Gangamin Google Analytics kamar yadda utm_medium = wasiku kai tsaye or binciken da aka biya.

(direct\smail|paid\ssearch)

  • Kuna so ku gwada duk samfuran da suke rigunan maza dangane da hanyar URL. Nemi Tsarin Tacewar URl:

^/mens/shirt/(.*)

  • Kuna so ku gwada dukkan shafukan da aka ƙidaya hanyar URL ɗin da ta ƙare tare da lambar. Nemi Tsarin Tacewar URl:

^/page/[1-9]*/$

  • Kuna son ware kewayon adiresoshin IP. Banda Tsarin Tace Adireshin IP:

123\.456\.789\.[0-9]

  • Kuna son haɗawa da shafin godiya.html inda ƙaddamarwa tayi nasara bisa ga nasarar nasara = gaskiya. Nemi Tsarin Tacewar URl:

thankyou\.html\?success=true

Yadda Ake Gwada maganganun Regex naka

Maimakon gwaji da kuskure a cikin Google Analytics, sau da yawa kawai ina tsallake zuwa wurin regex101, kayan aiki na kwarai don gwajin maganganunku na yau da kullun. Hakanan ya rusa maka tsarin aikinka kuma ya bada cikakkun bayanai game da maganganunka na yau da kullun:

maganganun yau da kullun regex101

Gina, Gwaji, da Debug Regex

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.