الفرق بين المراجعتين ل"Kotlin/kotlin.text/MatchResult/groups"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.groups</code> في لغة Kotlin}}</noinclude> تعيد الخاصية <code>groups</code> Kotlin/List|لا...')
 
ط
 
(3 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.groups</code> في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.groups</code> في Kotlin}}</noinclude>
تعيد الخاصية <code>groups</code> [[Kotlin/List|لائحة]] تضم مجموعة المُطابقات  <nowiki/>[[Kotlin/kotlin.text/Regex/index|للتعبير النمطي]]. حجم تلك [[Kotlin/List|اللائحة]] يساوي <code>groupCount + </code> حيث<code>groupCount</code> هو عدد المجموعات المطابَقة في  <nowiki/>[[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. تلك المجموعات مُفهرسة من 1 حتى <code>groupCount،</code> والمجموعة ذات الفهرس <code>0</code> توافق المطابقة الكلية.
+
تمثل الخاصية <code>MatchResult.groups</code> [[Kotlin/collections|مجموعةً]] (collection) تضم جميع المجموعات (groups) المتطابقة باستعمال <nowiki/>[[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد. حجم تلك [[Kotlin/collections|المجموعة]] يساوي <code>groupCount + 1</code>، إذ يكون <code>groupCount</code> عددَ المجموعات (groups) المتطابقة في [[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. تلك المجموعات مُفهرسةٌ بدءًا من العدد 1 وحتى <code>groupCount</code>، والمجموعة ذات الفهرس 0 توافق كل ما تطابق.
 
 
إن كانت المجموعة في  <nowiki/>[[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]<nowiki/>اختيارية ولم يكن هناك أي تطابق، فإن العنصر المقابل في [[Kotlin/List|اللائحة]] <code>groupValues</code> سيكون هو [[Kotlin/List|اللائحة]] الفارغة.
 
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
abstract val groupValues: List<String>
+
abstract val groups: MatchGroupCollection
  
 
</syntaxhighlight>
 
</syntaxhighlight>
==القيمة المُعادة==
+
==القيمة المعادة==
[[Kotlin/List|لائحة]] تضم مجموعة المُطابقات  <nowiki/>[[Kotlin/kotlin.text/Regex/index|للتعبير النمطي]].
+
يعاد كائن من النوع <code>[[Kotlin/kotlin.text/MatchGroupCollection/index|MatchGroupCollection]]</code> يمثل [[Kotlin/collections|مجموعة]] (collection) تضم جميع المجموعات (groups) المتطابقة باستعمال [[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد.
 
==أمثلة==
 
==أمثلة==
===استخدام الخاصية <code>groups</code>===
+
في الشيفرة التالية، ننشِئ <nowiki/>[[Kotlin/kotlin.text/Regex/index|تعبيرًا نمطيًا]] باسم <code>regex</code> باستخدام التابع <code>[[Kotlin/kotlin.text/Regex/Init|Regex()‎]]</code>، ثم نعرّف سلسلة نصية باسم <code>str</code>، ثم نستخرج منها مجموعات النتائج عبر استدعاء الدالة <code>matchEntire()‎</code>. نستخدم بعدئذٍ الخاصية <code>MatchResult.groups</code> لاستخراج المجموعات المتطابقة الموجودة في السلسلة <code>str</code>، ثم نطبع الناتج:<syntaxhighlight lang="kotlin">
في الشيفرة التالية ننشِئ  <nowiki/>[[Kotlin/kotlin.text/Regex/index|تعبيرًا نمطيًا]] باسم <code>regex</code> باستخدام التابع <code>[[Kotlin/kotlin.text/Regex/Init|Regex()‎]]</code>، ثم نعرّف سلسلة نصية باسم <code>str</code>، ثم نستخرج من <code>str</code>  مجموعات النتائج عبر استدعاء الدالة <code>matchEntire()‎</code>، ثم نستخدم الخاصية <code>groups</code> لاستخراج مجموعات النتائج، ثم نطبع الناتج:<syntaxhighlight lang="kotlin">
 
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
val pattern = Regex("[a-zA-Z]+([0-9]+)[a-zA-Z]+([0-9]+)[a-zA-Z]+")
+
    val pattern = Regex("[a-zA-Z]+([0-9]+)[a-zA-Z]+([0-9]+)[a-zA-Z]+")
val str = "ABcDEFG12345DiFKGLSG938SDsFSd"
+
    val str = "ABcDEFG12345DiFKGLSG938SDsFSd"
  
val res = pattern.matchEntire(str)?.groupValues
+
    val res = pattern.matchEntire(str)?.groups
print(res)
+
    print(res)
 
}
 
}
 +
</syntaxhighlight>ناتج تنفيذ هذه الشيفرة هو ما يلي:<syntaxhighlight lang="kotlin">
 +
[MatchGroup(value=ABcDEFG12345DiFKGLSG938SDsFSd, range=0..28), MatchGroup(value=12345, range=7..11), MatchGroup(value=938, range=20..22)]
 
</syntaxhighlight>
 
</syntaxhighlight>
==أنظر أيضًا==
+
==انظر أيضًا==
* صفحة الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured/index|Destructured]]</code>.
+
*الدالة <code>[[Kotlin/kotlin.text/MatchResult/next|next()‎]]</code>: تعيد كائنًا من النوع <code>[[Kotlin/kotlin.text/MatchResult/index|MatchResult]]</code> يحوي ناتج المطابقة التالية [[Kotlin/kotlin.text/Regex/index|لتعبير نمطي]] محدد والذي يبدأ عند الفهرس الذي انتهت عنده آخر عملية مطابقة.
* الخاصية <code>MatchResult.destructured‎</code>: الخاصية <code>destructured‎</code> تعيد نسخة من الصنف <code>MatchResult.Destructured،</code> والتي توفّر مركبات لتفكيك قيم المجموعة المُطابقة. المركبة الأولى تقابل قيمة المجموعة المُطابقَة الأولى، والمركبة الثانية تقابل الثانية، وهكذا دواليك.
+
*الخاصية <code>[[Kotlin/kotlin.text/MatchResult/destructured|MatchResult.destructured‎]]</code>: تمثل نسخةً من الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured|Destructured]]</code> توفّر مكونات عملية الإسناد بالتفكيك (destructuring assignment) التي تطبق على قيم المجموعة المُطابقة.
 +
*الخاصية <code>[[Kotlin/kotlin.text/MatchResult/groupValues|MatchResult.groupValues]]</code>: تمثل [[Kotlin/collection/List|قائمة]] بقيم المجموعة المفهرسة المتطابقة.
 +
*الخاصية <code>[[Kotlin/kotlin.text/MatchResult/range|MatchResult.range]]</code>: تمثل مجال الفهارس الذي يحدد مكان مُطابقة [[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد في السلسلة النصية الأصلية.
 +
*الخاصية <code>[[Kotlin/kotlin.text/MatchResult/value|MatchResult.value]]</code>: تمثل [[Kotlin/String|السلسلة النصية]] المُدخلة، أو جزءًا منها، والمُطابقة [[Kotlin/kotlin.text/Regex/index|للتعبير النمطي]]. 
  
 
==مصادر==
 
==مصادر==
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/group-values.html الخاصية MatchResult.groups في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/groups.html صفحة الخاصية MatchResult.groups في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Property]]
 
[[تصنيف:Kotlin Property]]
 +
[[تصنيف:Kotlin Text]]
 +
[[تصنيف:Kotlin MatchResult]]

المراجعة الحالية بتاريخ 07:09، 30 أغسطس 2018

تمثل الخاصية MatchResult.groups مجموعةً (collection) تضم جميع المجموعات (groups) المتطابقة باستعمال تعبير نمطي محدد. حجم تلك المجموعة يساوي groupCount + 1، إذ يكون groupCount عددَ المجموعات (groups) المتطابقة في التعبير النمطي. تلك المجموعات مُفهرسةٌ بدءًا من العدد 1 وحتى groupCount، والمجموعة ذات الفهرس 0 توافق كل ما تطابق.

البنية العامة

abstract val groups: MatchGroupCollection

القيمة المعادة

يعاد كائن من النوع MatchGroupCollection يمثل مجموعة (collection) تضم جميع المجموعات (groups) المتطابقة باستعمال تعبير نمطي محدد.

أمثلة

في الشيفرة التالية، ننشِئ تعبيرًا نمطيًا باسم regex باستخدام التابع Regex()‎، ثم نعرّف سلسلة نصية باسم str، ثم نستخرج منها مجموعات النتائج عبر استدعاء الدالة matchEntire()‎. نستخدم بعدئذٍ الخاصية MatchResult.groups لاستخراج المجموعات المتطابقة الموجودة في السلسلة str، ثم نطبع الناتج:

fun main(args: Array<String>) {
    val pattern = Regex("[a-zA-Z]+([0-9]+)[a-zA-Z]+([0-9]+)[a-zA-Z]+")
    val str = "ABcDEFG12345DiFKGLSG938SDsFSd"

    val res = pattern.matchEntire(str)?.groups
    print(res)
}

ناتج تنفيذ هذه الشيفرة هو ما يلي:

[MatchGroup(value=ABcDEFG12345DiFKGLSG938SDsFSd, range=0..28), MatchGroup(value=12345, range=7..11), MatchGroup(value=938, range=20..22)]

انظر أيضًا

مصادر