# CountRegEx - Komut dosyası ve grafik fonksiyonu

CountRegEx(), giriş dizesi metninde belirtilen alt normal ifade deseni oluşlarının sayısını döndürür. Eşleşme yoksa, 0 sonucu döndürülür.

Bu fonksiyon, büyük/küçük harfe duyarlı regex işlemleri gerçekleştirir. Büyük/küçük harfe duyarlı olmayan regex işlemleri gerçekleştirmek için alternatif olarak CountRegExI() varyantını kullanabilirsiniz.

Söz Dizimi:

CountRegEx (text, regex)

Dönüş verileri türü: sayısal

Bağımsız Değişkenler

| Bağımsız Değişken | Açıklama |
| --- | --- |
| text | İçinde normal ifade aramak istediğiniz giriş dizesi metni. |
| regex | Aranacak normal ifade kalıbı. |

Fonksiyon örnekleri

| Örnek | Sonuç |
| --- | --- |
| `CountRegEx('abc123','[a-z]')` | `3` döndürür. |
| `CountRegEx('abc123','[a-z][0-9]')` | `1` döndürür. |
| `CountRegEx('abc123','[0-9]')` | `3` döndürür. |
| `CountRegEx('ABC','[a-z]{3}')` | `0` döndürür. |
| `CountRegExI('ABC','[a-z]{3}')` | `1` döndürür. CountRegExI() varyantı kullanıldığından, metin aramaları büyük/küçük harfe duyarlı değildir. |

## Ne zaman kullanılır?

CountRegEx() için kullanım örneklerine şunlar dahildir:

* Belirli bir metin kalıbının bir dize içinde kaç kez geçtiğini sayma. Örneğin, belgeler ve e-posta mesajları içinde e-posta adresleri, telefon numaraları ve diğer bilgilerin örneklerini arayabilirsiniz.

* Verilerin belirli bir söz dizimi gereksinimiyle eşleşip eşleşmediğini doğrulama. Örneğin, veri girişinde hata oluşumlarını tespit edebilirsiniz.

## Örnek 1 - geçerli yıl aralıklarını saymak için komut dosyası

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/CountRegEx.htm)

#### Yükleme kodu ve sonuçlar

Genel bakış

Veri yükleme düzenleyicisini açın ve aşağıdaki komut dosyasını yeni bir bölüme ekleyin.

Komut dosyası şunları içerir:

* Her bir aracın durumu ve model yılı ile birlikte araçların bir listesini içeren `Vehicles` adlı bir tablo.

* `Vehicles` içindeki her kayıt için, aracın yıl aralığının beklenen sözdizimini karşılayıp karşılamadığını belirlemek üzere bir hesaplama. Geçerli yıl aralıkları 1990'lar, 2000'ler, 2010'lar ve 2020'leri içerir. Bu hesaplama, CountRegEx() fonksiyonu kullanılarak gerçekleştirilir.

Komut dosyası

```
Vehicles:
Load CountRegEx(Model_YearRange, '(^19[0-9][0-9]s$)|(^20[0-9][0-9]s$)') as Valid_Year_Data,
* Inline [
Vehicle_ID, Condition, Model_YearRange
1, Good,20100s
2,Fair,2020s
3, Poor,2020s
4, Good,210s
5, Excellent,2000s
6, Excellent,2020s
7, Excellent,202s
8, Good,2010s
9, Poor,2010ss
10, Poor,1990s
];
```

Sonuçlar

Verileri yükleyin ve bir sayfa açın. Yeni bir tablo oluşturun ve şu alanları boyut olarak ekleyin:

* `Vehicle_ID`

* `Valid_Year_Data`

Sonuçlar tablosu

| Vehicle\_ID | Valid\_Year\_Data |
| --- | --- |
| 1 | 0 |
| 2 | 1 |
| 3 | 1 |
| 4 | 0 |
| 5 | 1 |
| 6 | 1 |
| 7 | 0 |
| 8 | 1 |
| 9 | 0 |
| 10 | 1 |

Ayrıca sayfaya bir KPI ekleyebilir ve bu hesaplamayı ekleyebilirsiniz:

```
Sum(Valid_Year_Data)
```

Bu grafik, geçerli Model\_YearRange değerlerine sahip toplam kayıt sayısını göstermektedir.

Bilgi notuMatchRegEx() fonksiyonu bu tür doğrulama kullanım durumları için de kullanışlıdır.

## Örnek 2 - Metin dizelerindeki e-posta adreslerini saymak için komut dosyası yükleme

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/CountRegEx.htm)

#### Yükleme kodu ve sonuçlar

Genel bakış

Veri yükleme düzenleyicisini açın ve aşağıdaki komut dosyasını yeni bir bölüme ekleyin.

Komut dosyası şunları içerir:

* Bir şirketin çalışanları hakkında veriler içeren `Employees` adlı bir tablo. Her çalışan için tüm e-posta adresleri tek bir dizede yer alır.

* Her bir çalışan için girdi dizesinde kaç e-posta adresi bulunduğunu hesaplamak üzere `NoOfEmails` alanının oluşturulması.

Komut dosyası

```
Employees:

Load CountRegExI(Emails, '@[a-zA-Z0-9.-]*\.?[a-zA-Z0-9]*\.com') as NoOfEmails,
* Inline `
ID	Emails
1	john_doe@test.com john_michael_doe@example.com j.doe123@example123.com
2	jane_doe@test.com
3	Michael_Andrews@test.com Michael_John_Andrews@example.com
4	charlie_kent@support.test.com charlie_peter_kent@support.example.com cp.kent.1985@test123.com c_p_kent@test123.com
5	frances_johnson@test.com frances_johnson@example.com
6	rebecca_smith@hr.test.com
` (delimiter is '\t');
```

Sonuçlar

Verileri yükleyin ve bir sayfa açın. Yeni bir tablo oluşturun ve şu alanları boyut olarak ekleyin:

* `ID`

* `Emails`

* `NoOfEmails`

Sonuçlar tablosu

| ID | Emails | NoOfEmails |
| --- | --- | --- |
| 1 | john\_doe@test.com john\_michael\_doe@example.com j.doe123@example123.com | 3 |
| 2 | jane\_doe@test.com | 1 |
| 3 | Michael\_Andrews@test.com Michael\_John\_Andrews@example.com | 2 |
| 4 | charlie\_kent@support.test.com charlie\_peter\_kent@support.example.com cp.kent.1985@test123.com c\_p\_kent@test123.com | 4 |
| 5 | frances\_johnson@test.com frances\_johnson@example.com | 2 |
| 6 | rebecca\_smith@hr.test.com | 1 |

## Örnek 3 - dizenin oluşlarını saymak için grafik ifadesi

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/CountRegEx.htm)

#### Grafik ifadesi ve sonuçlar

Genel bakış

Veri yükleme düzenleyicisi bölümünü açın ve aşağıdaki yükleme kodunu yeni bir bölüme ekleyin.

Komut dosyası, bir kuruluşun çalışanlarına gönderilen bir dizi kurumsal yazışmanın metnini içerir. Veriler, şirket adı ve her bir yazışmanın gönderildiği e-posta adresi dışındaki tüm kişisel tanımlanabilir bilgilerden (PII) zaten temizlenmiştir. Her bir mesajın gövdesi tek bir kesintisiz dizeye dönüştürülmüştür. Başka bir deyişle, tüm biçimlendirme ve satır sonu karakterleri kaldırılmıştır.

Gereksinimlerimiz:

* Hangi iletilerin TestCompanyNameCorrespondence@test.com e-posta adresini içeren bir dize ve bu adrese gönderenin o olduğunu belirten özel bir giriş içerdiğini belirleyin.

* Hangi tanıtımların tanımlanacağı konusunda esneklik istiyoruz, ancak yine de bazı kesin kısıtlamalara sahip olmak istiyoruz. Sender ve Sent by tanıtımlarının her ikisi de geçerli kabul edilir. Bu amaca ulaşmak için regex kalıpları kullanılabilir.

* E-posta adreslerinin büyük/küçük harf duyarlılığı bir faktör değildir. Bu nedenle, arama büyük/küçük harfe duyarsız olmalıdır.

Komut dosyası

```
Correspondences:
Load * Inline [
ID|MessageBody
1|Sent by-- TestCompanyNameCorrespondence@test.com Good morning TestCompanyName team! I hope you are all well. I am just reaching out about the fabulous benefits package we launched just year. Our goal is to take a poll of what you all think. Can you please rate the new options from 1-10 in a response to this email, by this Tuesday? Thank you! 
2|Sender: TestCompanyNameIT@test.com Did you know you can access our IT portal anytime, from any of your company devices? It's true! Reach out to your team lead to learn more.
3|Sender: TESTCOMPANYNAMECORRESPONDENCE@test.COM URGENT: This is a message to inform employees of an ongoing issue with our local branch. The branch will be closed until further notice. Thank you
4|Sender: TestCompanyNameVolunteering@test.com Dear team! We are looking for volunteers to help with this year's charity event! We need 40 volunteers to help with the event. If you are interested, please send an email to your direct supervisor. Thanks, TestCompanyName team members, for helping make the world a better place!
5|Sender is TestCompanyNameCorrespondence@test.com Hi folks, it's time to announce the annual TestCompanyName staff party! The party will be taking place at the office this year. Please make sure to RSVP, and we hope to see you there! Sincerely, the TestCompanyName management team
] (delimiter is |);
```

Sonuçlar

Verileri yükleyin ve bir sayfa açın. Yeni bir tablo oluşturun ve şu alanları boyut olarak ekleyin:

* ID

* MessageBody

Aşağıdaki hesaplamayı ekleyin:

```
=CountRegExI(MessageBody,'(Sender.*TestCompanyNameCorrespondence@test.com)|(Sent by.*TestCompanyNameCorrespondence@test.com)')
```

Hesaplama özelliklerinde, Toplamlar fonksiyonunu Sum olarak ayarlayın. Bu, tablonun üst kısmındaki toplamlar satırını, sayıma katkıda bulunan toplam kayıt sayısını sayacak şekilde yapılandırır.

Hesaplama, ileti içeriğinde belirtilen regex deseni için eşleşme sayısını sayar. Regex deseninde .\*, satır sonu karakterleri hariç herhangi bir karakter sayısını gösterir. Kalıp ayrıca e-posta adresinin nasıl tanıtıldığına ilişkin farklılıkları da açıklar: hem Sender hem de Sent by geçerli eşleşmelerdir. Fonksiyonun CountRegExI() varyantı büyük/küçük harfe duyarsız arama yapılmasını sağlar.

Sonuçlar tablosu

| ID | MessageBody | =CountRegExI(MessageBody,'(Sender.\*TestCompanyNameCorrespondence@test.com)\|(Sent by.\*TestCompanyNameCorrespondence@test.com)') |
| --- | --- | --- |
| Totals | - | 3 |
| 1 | Sent by-- TestCompanyNameCorrespondence@test.com Good morning TestCompanyName team! I hope you are all well. I am just reaching out about the fabulous benefits package we launched just year. Our goal is to take a poll of what you all think. Can you please rate the new options from 1-10 in a response to this email, by this Tuesday? Thank you! | 1 |
| 2 | Sender: TestCompanyNameIT@test.com Did you know you can access our IT portal anytime, from any of your company devices? It's true! Reach out to your team lead to learn more. | 0 |
| 3 | Sender: TESTCOMPANYNAMECORRESPONDENCE@TEST.COM URGENT: This is a message to inform employees of an ongoing issue with our local branch. The branch will be closed until further notice. Thank you | 1 |
| 4 | Sender: TestCompanyNameVolunteering@test.com Dear team! We are looking for volunteers to help with this year's charity event! We need 40 volunteers to help with the event. If you are interested, please send an email to your direct supervisor. Thanks, TestCompanyName team members, for helping make the world a better place! | 0 |
| 5 | Sender is TestCompanyNameCorrespondence@test.com Hi folks, it's time to announce the annual TestCompanyName staff party! The party will be taking place at the office this year. Please make sure to RSVP, and we hope to see you there! Sincerely, the TestCompanyName management team | 1 |

Beş mesaj arasında, belirtilen regex deseniyle eşleşen üç mesaj vardır. Her mesaj bir eşleşme içerir.

Bilgi notuMatchRegEx() fonksiyonu bu tür doğrulama kullanım durumları için de kullanışlıdır.

## Daha fazla bilgi

* [Komut dosyalarında ve grafik ifadelerinde normal ifadelerle çalışma](https://help.qlik.com/tr-TR/sense/November2025/Subsystems/Hub/Content/Sense_Hub/Scripting/regular-expressions-qlik-analytics.htm)