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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.range</code> في لغة Kotlin}}</noinclude> تعيد الخاصية <code>range</code> كائنًا من...')
 
ط
 
(4 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.range</code> في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الخاصية <code>MatchResult.range</code> في Kotlin}}</noinclude>
تعيد الخاصية <code>range</code> كائنًا من النوع <code>[[Kotlin/kotlin.text/MatchGroupCollection/index|MatchGroupCollection]]</code> يضم مجموعة المُطابقات الموجودة في  [[Kotlin/kotlin.text/Regex/index|ا]]<nowiki/>[[Kotlin/kotlin.text/Regex/index|لتعبير النمطي]]. حجم تلك المجموعة يساوي <code>groupCount + 1،</code> حيث<code>groupCount</code> هو عدد المجموعات المطابَقة في  <nowiki/>[[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. تلك المجموعات مُفهرسة من 1 حتى <code>groupCount،</code> والمجموعة ذات الفهرس <code>0</code> توافق المطابقة الكلية.
+
تمثل الخاصية <code>MatchResult.range</code> مجال الفهارس الذي يحدد مكان مُطابقة <nowiki/>[[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد في السلسلة النصية الأصلية.
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="kotlin">
 
<syntaxhighlight lang="kotlin">
abstract val groups: MatchGroupCollection
+
abstract val range: IntRange
  
 
</syntaxhighlight>
 
</syntaxhighlight>
==القيمة المُعادة==
+
==القيمة المعادة==
كائن من النوع <code>[[Kotlin/kotlin.text/MatchGroupCollection/index|MatchGroupCollection]].</code>
+
يعاد مجالٌ من النوع <code>[[Kotlin/ranges/IntRange|IntRange]]</code> يمثل الفهارس التي تحدد مكان مُطابقة [[Kotlin/kotlin.text/Regex/index|تعبير نمطي]] محدد في السلسلة النصية الأصلية.
 
==أمثلة==
 
==أمثلة==
===استخدام الخاصية <code>range</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.range</code> لاستخراج الفهارس التي تحدد مكان مُطابقة [[Kotlin/kotlin.text/Regex/index|التعبير النمطي]] <code>regex</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>range</code> لاستخراج مجموعات مجموعة المُطابقات الموجودة في <code>str</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)?.groups
+
    val res = pattern.matchEntire(str)?.range
print(res)
+
 
 +
    print(res) // 0..28
 
}
 
}
</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|MatchResult.destructured‎]]</code>: تعيد نسخة من الصنف <code>[[Kotlin/kotlin.text/MatchResult/Destructured/index|MatchResult.Destructured]]،</code> والتي توفّر مركبات لتفكيك قيم المجموعة المُطابقة. المركبة الأولى تقابل قيمة المجموعة المُطابقَة الأولى، والمركبة الثانية تقابل الثانية، وهكذا دواليك.
+
*الدالة <code>[[Kotlin/kotlin.text/MatchResult/next|next()‎]]</code>: تعيد كائنًا من النوع <code>[[Kotlin/kotlin.text/MatchResult/index|MatchResult]]</code> يحوي ناتج المطابقة التالية [[Kotlin/kotlin.text/Regex/index|لتعبير نمطي]] محدد والذي يبدأ عند الفهرس الذي انتهت عنده آخر عملية مطابقة.
* الخاصية <code>[[Kotlin/kotlin.text/MatchResult/groupValues|MatchResult.groupValues]]</code>: تعيد  [[Kotlin/List|لائحة]] تضم مجموعة المُطابقات  <nowiki/>[[Kotlin/kotlin.text/Regex/index|للتعبير النمطي]]. حجم تلك [[Kotlin/List|اللائحة]] يساوي <code>groupCount + 1،</code> حيث<code>groupCount</code> هو عدد المجموعات المطابَقة في  <nowiki/>[[Kotlin/kotlin.text/Regex/index|التعبير النمطي]]. تلك المجموعات مُفهرسة من 1 حتى <code>groupCount،</code> والمجموعة ذات الفهرس <code>0</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/groups|MatchResult.groups]]</code>: تمثل [[Kotlin/collections|مجموعةً]] (collection) تضم جميع المجموعات (groups) المتطابقة باستعمال [[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/groups.html الخاصية MatchResult.range في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
* [http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/range.html صفحة الخاصية MatchResult.range في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin Property]]
 
[[تصنيف:Kotlin Property]]
 +
[[تصنيف:Kotlin Text]]
 +
[[تصنيف:Kotlin MatchResult]]

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

تمثل الخاصية MatchResult.range مجال الفهارس الذي يحدد مكان مُطابقة تعبير نمطي محدد في السلسلة النصية الأصلية.

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

abstract val range: IntRange

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

يعاد مجالٌ من النوع IntRange يمثل الفهارس التي تحدد مكان مُطابقة تعبير نمطي محدد في السلسلة النصية الأصلية.

أمثلة

في الشيفرة التالية، ننشِئ تعبيرًا نمطيًا باسم regex باستخدام التابع Regex()‎، ثم نعرّف سلسلة نصية باسم str، ثم نستخرج منها مجموعات النتائج عبر استدعاء الدالة matchEntire()‎. نستخدم بعدئذٍ الخاصية MatchResult.range لاستخراج الفهارس التي تحدد مكان مُطابقة التعبير النمطي regex في السلسلة النصية 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)?.range

    print(res) // 0..28
}

انظر أيضًا

مصادر