222 subscribers
148 photos
1 video
42 files
64 links
تجميع أكبر كم من المعلومات حول مجالات التقنية
(#linux - #backend - #frontend - #ai - #Network - #php - #python)

Follow me:
Linkedin: https://linkedin.com/in/fadlhasn
Twitter:https://twitter.com/fdl_hasn

Connect me:
@FadL_Hasn
Download Telegram
Regular Expressions
التعابير النمطية (Regular Expressions - RegEx) عبارة عن مجموعة من الرموز والأحرف مكتوبة بنمط معين وبترتيب معين (Pattern)، تُستخدم في التعامل مع النصوص. يمكن استخدامها في عمليات البحث عن نماذج محددة في النص، التحقق من شروط معينة في النص، واستخراج المعلومات من النص بسهولة دون الاعتماد على خوارزميات معقدة.


يعد التعبير العادي، أو #regex أو #regexp باختصار، قويًا للغاية ومدهشًا في البحث عن السلاسل النصية ومعالجتها، خاصة في معالجة الملفات النصية. يمكن لسطر واحد من التعبير العادي أن يحل محل عشرات الأسطر من أكواد البرمجة بسهولة.

يتم دعم Regex بجميع لغات البرمجة النصية (مثل #Perl و #Python و #PHP و #JavaScript)؛ بالإضافة إلى لغات البرمجة للأغراض العامة(غرضية التوجه) مثل #Java؛ وحتى معالجات النصوص مثل برنامج ال Word للبحث في النصوص. قد لا يكون البدء في استخدام regex أمرًا سهلاً نظرًا لتركيبه العبقري غريب الأطوار، ولكنه بالتأكيد يستحق استثمار وقتك.
🔰Examples :
python example in terminal🔴🐍 :

# Test under the Python Command-Line Interpreter
$ python3
......
>>> import re # Need module 're' for regular expression

# Try find: re.findall(regexStr, inStr) -> matchedSubstringsList
# r'...' denotes raw strings which ignore escape code, i.e., r'\n' is '\'+'n'
>>> re.findall(r'[0-9]+', 'abc123xyz')
['123'] # Return a list of matched substrings
>>> re.findall(r'[0-9]+', 'abcxyz')
[]
>>> re.findall(r'[0-9]+', 'abc00123xyz456_0')
['00123', '456', '0']
>>> re.findall(r'\d+', 'abc00123xyz456_0')
['00123', '456', '0']

# Try substitute: re.sub(regexStr, replacementStr, inStr) -> outStr
>>> re.sub(r'[0-9]+', r'*', 'abc00123xyz456_0')
'abc*xyz*_*'

# Try substitute with count: re.subn(regexStr, replacementStr, inStr) -> (outStr, count)
>>> re.subn(r'[0-9]+', r'*', 'abc00123xyz456_0')
('abc*xyz*_*', 3) # Return a tuple of output string and count


js example :

<!DOCTYPE html>
<!-- JSRegexNumbers.html -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Example: Regex</title>
<script>
var inStr = "abc123xyz456_7_00";

// Use RegExp.test(inStr) to check if inStr contains the pattern
console.log(/[0-9]+/.test(inStr)); // true

// Use String.search(regex) to check if the string contains the pattern
// Returns the start position of the matched substring or -1 if there is no match
console.log(inStr.search(/[0-9]+/)); // 3

// Use String.match() or RegExp.exec() to find the matched substring,
// back references, and string index
console.log(inStr.match(/[0-9]+/)); // ["123", input:"abc123xyz456_7_00", index:3, length:"1"]
console.log(/[0-9]+/.exec(inStr)); // ["123", input:"abc123xyz456_7_00", index:3, length:"1"]

// With g (global) option
console.log(inStr.match(/[0-9]+/g)); // ["123", "456", "7", "00", length:4]

// RegExp.exec() with g flag can be issued repeatedly.
// Search resumes after the last-found position (maintained in property RegExp.lastIndex).
var pattern = /[0-9]+/g;
var result;
while (result = pattern.exec(inStr)) {
console.log(result);
console.log(pattern.lastIndex);
// ["123"], 6
// ["456"], 12
// ["7"], 14
// ["00"], 17
}

// String.replace(regex, replacement):
console.log(inStr.replace(/\d+/, "**")); // abc**xyz456_7_00
console.log(inStr.replace(/\d+/g, "**")); // abc**xyz**_**_**
</script>
</head>
<body>
<h1>Hello,</h1>
</body>
</html>


🔰 Articles:
- Regular expressions - MDN
https://developer.mozilla.org/.../Guide/Regular_expressions
- A Step-by-Step Guide for Learning Regular Expressions: A Guide with Real-Life Usage
https://blogs.princegupta.me/a-step-by-step-guide-for...
- Regular Expressions Info
https://www.regular-expressions.info
- RegExOne
https://regexone.com
- RegEx Tutorial - java T point
https://www.javatpoint.com/regex
- RegExr learn ,build & test regEX
https://regexr.com/
- AI-Powered Regular Expression Solver
https://regex.ai/
-----
🔰 Videos:
- Regular Expressions (RegEx) Tutorial
https://youtube.com/playlist...
- Learn Regular Expressions (Regex) - Crash Course for Beginners
https://youtu.be/ZfQFUJhPqMM
- Regular Expression Tutorial - Arabic
https://youtube.com/playlist...
- Regular Expressions (Regex) Tutorial: How to Match Any Pattern of Text
https://youtu.be/sa-TUpSx1JA
- Complete Regular Expressions Tutorial! (with exercises for practice)
https://youtu.be/vsa9GGzMFXQ
- CS50P - Lecture 7 - Regular Expressions
https://youtu.be/hy3sd9MOAcc
--------

#regEx #regExp #RegulerExpression #pattern #regEx_tutorial #python_regEx #js_regEX
IT Engineer
Regular_Expressions_Cheat_Sheet.pdf
من أفضل أوراق غش لتعلم regEx
#regEx #book #cheatSheet