freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../regular-expressions/match-beginning-string-patt...

2.8 KiB

id title challengeType videoUrl localeTitle
587d7db7367417b2b2512b9d Match Beginning String Patterns 1 مباراة بداية أنماط سلسلة

Description

أظهرت التحديات السابقة أنه يمكن استخدام التعبيرات العادية للبحث عن عدد من التطابقات. كما يتم استخدامها للبحث عن أنماط في مواضع محددة في السلاسل. في تحدي سابق ، استخدمت caret ( ^ ) داخل مجموعة character set لإنشاء مجموعة negated character set [^thingsThatWillNotBeMatched] في النموذج [^thingsThatWillNotBeMatched] . خارج مجموعة character set ، يتم استخدام caret للبحث عن الأنماط في بداية السلاسل.
let firstString = "Ricky is first and can be found."؛
let firstRegex = / ^ Ricky /؛
firstRegex.test (firstString)؛
// يعود صحيح
let notFirst = "لا يمكنك العثور على Ricky الآن."؛
firstRegex.test (notFirst)؛
// إرجاع خاطئة

Instructions

استخدم caret في تعبير منطقي للبحث عن "Cal" فقط في بداية السلسلة rickyAndCal .

Tests

tests:
  - text: يجب أن يبحث التعبير المعتاد عن <code>&quot;Cal&quot;</code> بحرف كبير.
    testString: 'assert(calRegex.source == "^Cal", "Your regex should search for <code>"Cal"</code> with a capital letter.");'
  - text: يجب ألا يستخدم تعبيرك المعتاد أي أعلام.
    testString: 'assert(calRegex.flags == "", "Your regex should not use any flags.");'
  - text: يجب أن يتطابق تعبيرك العادي مع كلمة <code>&quot;Cal&quot;</code> في بداية السلسلة.
    testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match <code>"Cal"</code> at the beginning of the string.");'
  - text: يجب ألا يتطابق التعبير العادي مع <code>&quot;Cal&quot;</code> في وسط سلسلة.
    testString: 'assert(!calRegex.test("Ricky and Cal both like racing."), "Your regex should not match <code>"Cal"</code> in the middle of a string.");'

Challenge Seed

let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);

Solution

// solution required