Regex نمونہ ٹیسٹر

استعمال کا طریقہ 3 مراحل
  1. Regex پیٹرن اور جھنڈے لکھیں۔
  2. ٹیسٹ عبارت چسپاں کریں۔
  3. پیٹرن کی مطابقت جانچیں دبائیں اور نمایاں مماثلتیں اور گروپس دیکھیں۔
پیٹرن کی مطابقتوں کا نتیجہ

یہ ٹول کیسے کام کرتا ہے

آپ کا درج کردہ نمونہ JavaScript کے ریگولر ایکسپریشن کے طور پر مرتب ہو کر آپ کی آزمائشی سٹرنگ پر چلایا جاتا ہے، اور ہر مماثلت گنتی کے ساتھ فہرست میں آتی ہے۔ جھنڈے الگ درج ہوتے ہیں: g پہلی پر رکنے کے بجائے ہر مماثلت ڈھونڈتا ہے، i حروف کی نوعیت نظر انداز کرتا ہے، m شروع اور آخر کے لنگر ہر سطر پر لگاتا ہے، اور s نقطے کو نئی سطر سے میل کھانے دیتا ہے۔

یہاں کا ریگولر ایکسپریشن انجن براؤزر کا ہے، وہی جو آپ کا JavaScript استعمال کرے گا۔ یہ جاننا اس لیے فائدہ مند ہے کہ نحو عالمگیر نہیں: PHP، Python یا کسی ایڈیٹر کے لیے لکھے گئے نمونے ایسی خصوصیات استعمال کر سکتے ہیں جو JavaScript میں نہیں، اور خاص طور پر lookbehind کی معاونت کی تاریخ مختلف ہے۔ اگر نمونہ مرتب نہ ہو سکے تو عام ناکامی کے بجائے انجن کا اپنا پیغام دکھایا جاتا ہے۔

ایسا نمونہ بنانا جو نبھ جائے

  • g جھنڈے کے بغیر ایک ہی مماثلت ملتی ہے: گنتی پہلے موقع پر رک جاتی ہے، اور عموماً یہی وجہ ہے کہ چلتا ہوا نمونہ اپنی توقع سے کہیں کم ڈھونڈتا دکھائی دیتا ہے۔
  • ایسی عبارت پر آزمائیں جس سے میل نہیں کھانا چاہیے: جو نمونہ آپ کی مطلوبہ چیز سے میل کھائے وہ آدھی بات ہے۔ پروڈکشن تک پہنچنے والی غلطیاں وہ نمونے ہیں جو مقصود سے زیادہ سے میل کھاتے ہیں۔
  • ایک دوسرے کے اندر آنے والے مقدار نشان صفحہ روک سکتے ہیں: ایسا نمونہ جس میں ایک تکرار دوسری کے اندر ہو، تقریباً میل کھانے والے ان پُٹ پر بے پناہ وقت لے سکتا ہے۔ اگر کوئی آزمائش جمی ہوئی لگے تو عموماً یہی وجہ ہوتی ہے۔
  • جو لفظی مراد ہو اسے محفوظ کریں: نقطہ ہر حرف سے میل کھاتا ہے جب تک اسے محفوظ نہ کیا جائے، اسی لیے فائل کے نام یا پتے سے میل کھانے کے لیے بنے نمونے خاموشی سے توقع سے کہیں زیادہ سے میل کھا جاتے ہیں۔

Compiled by the same engine your JavaScript will use

A pattern entered into the [msm_tool slug="regex-tester"] is compiled as an actual JavaScript regular expression and run for real, using the browser's own engine — the same one any JavaScript on the page would use. That matters because regex syntax is not universal: a pattern written for PHP, Python or a text editor can rely on features JavaScript does not have, and lookbehind in particular has a genuinely uneven support history across engines.

Without the g flag, you get exactly one match

Leaving the global flag off stops the search at the very first occurrence, which is the ordinary reason a pattern that clearly looks correct appears to find far less than it should. Adding it is usually the entire fix for a match count that seems inexplicably low.

Nested quantifiers can hang the page

A pattern with one repetition nested inside another can take exponential time against input that almost matches but not quite, which is exactly the shape of input most likely to appear in practice. If a test seems to freeze rather than simply run slowly, this is almost always why — and the same pattern would cause the identical problem running in production, not just here.

A dot matches everything until it is told not to

An unescaped dot matches any character at all, which is why a pattern meant to match a filename or an email address quietly matches a great deal more than intended unless the dot is escaped where a literal period is actually meant. This is one of the most common gaps between what a pattern was meant to do and what it actually does.

Test against what should not match, not only what should

A pattern that correctly matches the intended input is only half the job done. The mistakes that make it into production are almost always patterns that match more than intended, which only shows up by deliberately testing against text the pattern is supposed to reject.

What it will not show you

Whole matches are listed along with a total count, but individual capture groups are not broken out separately here. Inspecting a pattern group by group means running it in actual code, where each group can be read directly rather than inferred from the whole match.

اکثر پوچھے گئے سوالات

خاص طور پر Regex نمونہ ٹیسٹر کے بارے میں۔ اس زمرے سے متعلق عمومی سوالات کے جواب زمرے کے صفحے پر موجود ہیں۔

g جھنڈا موجود نہیں۔ اس کے بغیر تلاش پہلے موقع پر رک جاتی ہے۔
زیادہ تر، مگر پوری طرح نہیں۔ یہ براؤزر کا انجن استعمال کرتا ہے، اس لیے کسی دوسری زبان کی مخصوص خصوصیات پر انحصار کرنے والا نمونہ مختلف برتاؤ کر سکتا ہے یا مرتب ہی نہ ہو۔
g ہر مماثلت ڈھونڈتا ہے، i حروف کی نوعیت نظر انداز کرتا ہے، m لنگر ہر سطر پر لگاتا ہے، s نقطے کو نئی سطر سے میل کھانے دیتا ہے، u مکمل Unicode کی سنبھال آن کرتا ہے۔
غالباً ایک دوسرے کے اندر آنے والی تکرار۔ کچھ نمونے تقریباً میل کھانے والے ان پُٹ پر بے پناہ وقت لیتے ہیں، جس سے پروڈکشن میں بھی بچنا چاہیے۔
یہ پوری مماثلتیں اور ان کی گنتی دکھاتا ہے۔ گروہ در گروہ جانچ کے لیے نمونہ اپنے کوڈ میں چلائیں جہاں آپ ہر گروہ پڑھ سکیں۔

نئے ٹولز، خصوصیات اور کارکردگی بڑھانے کے مشوروں کی اطلاع پانے کے لیے سبسکرائب کریں۔