Code Module | کد ماژول
1.91K subscribers
357 photos
42 videos
6 files
355 links
Hello World 🌎

<> Earth is programmable if you code it </>

Group 👇🏻
@CodeModuleGap

Contact Us 👇🏻
@MrShahiin
@neoMahan
Download Telegram
😈 نحوه استفاده از Regex، در چند زبان مختلف برنامه نویسی

عبارات منظم یا
Regex، یک مجموعه از الگوها و نمادهای خاصه که برای جستجو، استخراج و تحلیل الگوهای خاص در رشته‌ها (متن‌ها) استفاده میشه. این الگوها می‌تونن الگوهای ساده مثل جستجوی یک کلمه خاص یا الگوهای پیچیده‌تر مثل جستجوی ایمیل‌ها، شماره تلفن‌ها، آدرس‌های اینترنتی و ... باشن.

😎بریم چند مثال از نحوه استفاده و سینتکسش در زبان های برنامه نویسی مختلف برسی کنیم:

⌨️ زبان برنامه نویسی PHP:

<?php
$text = "Hello, World! This is a sample text.";
$pattern = "/\b\w{5}\b/"; // Matches words with exactly 5 characters
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);
?>


✌️ زبان برنامه نویسی JavaScript:

let text = "Hello, World! This is a sample text.";
let pattern = /\b\w{5}\b/g; // Matches words with exactly 5 characters
let matches = text.match(pattern);
console.log(matches);


⌨️ زبان برنامه نویسی Python :

import re

text = "Hello, World! This is a sample text."
pattern = r'\b\w{5}\b' # Matches words with exactly 5 characters
matches = re.findall(pattern, text)
print(matches)


⌨️ زبان برنامه نویسی #C :

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string text = "Hello, World! This is a sample text.";
        string pattern = @"\b\w{5}\b"; // Matches words with exactly 5 characters
        MatchCollection matches = Regex.Matches(text, pattern);
        foreach (Match match in matches)
        {
            Console.WriteLine(match.Value);
        }
    }
}


در این مثال‌ها یک الگو Regex برای پیدا کردن کلماتی با طول ۵ حرف در یک متن مشخص، تعریف شده. همچنین میتونید پترن های کاستوم شده تری با توجه به نیازتون بنویسید 🔥

#regex #language
@CodeModule
Please open Telegram to view this post
VIEW IN TELEGRAM
9🔥3😁1💔1