ویکی‌پدیا:ویرایشگر خودکار/عبارت باقاعده

نماگرفت از سایت https://regexr.com/ برای کار کردن با عبارت با قاعده

تعریف عبارت‌های باقاعده ویرایش

عبارت‌های باقاعده (.NET)
لنگر توضیح
^ آغاز رشته نخستین رشتهٔ صفحه
\A آغاز رشته نخستین رشتهٔ صفحه
$ پایان رشته رشتهٔ پایانی صفحه
\Z پایان رشته رشتهٔ پایانی صفحه
\b مرز روی یک واژه On a letter, تعداد رشتهٔ زیرخط
\B مرز روی یک واژه نیست Not on a letter, تعداد رشتهٔ زیرخط
 
دستهٔ رشته مثال
\w یک نوع رشتهٔ مجاز در نام متغیر (حرف، رقم، زیرخط) abcdefghijklmnopqstuvwxyz​ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789_
\W یک رشتهٔ غیرمجاز در نام متغیر $?!#%*@&;:.,+-±=^"`\|/<>{}[]()~(newline)(tab)(space)
\s یک رشتهٔ فاصله (فاصله) (پرش) (خط جدید) (برگشت)
\S یک رشته به جز فاصله abcxyz_ABCXYZ$?!#%*@&;:.,+-=^"/<{[(~0123789 (incomplete list)
\d یک رقم 0123456789
\D یک رشتهٔ غیر رقم abcxyz_ABCXYZ$?!#%*@&;:.,+-=^"/<{[(~(newline)(tab)(space) (incomplete list)
\n خط جدید (خط جدید)
\t پرش (پرش)
\c رشتهٔ کنترل
\x رقم شانزدهی 0123456789abcdefABCDEF
\0 رقم هشتایی 01234567
 
تعداد توضیح
* ۰ یا بیشتر
+ ۱ یا بیشتر
? ۰ یا ۱
{3} دقیقاً ۳
{3,} ۳ یا بیشتر
{2,4} ۲، ۳ یا ۴
 
رشتهٔ فرار توضیح
\ Escape Character
 
Metacharacters (must be escaped) Comments
رشتهٔ عملگر Metacharacter escaped  
^ \^
$ \$
( \(
) \)
< \<
. \.
* \*
+ \+
? \?
[ \[
] \]
{ \{
\ \\
| \|
> \>
  در این فهرست نیست: =}#!/%&_:; (فهرست ناقص)
Groups and Ranges
Note: Ranges are inclusive
توضیح
. یک رشته جز خط جدید
( . . . ) Capture group (captures anything between the parentheses) Backreference captured groups with $1 $2 etc.
(abc) abc (in sequence) $1 $2 $3 etc. are called backreferences.
| Alternation (matches either the right side or the left)
ab|cd|ef ab or cd or ef
[def] d or e or f
[^abc] Anything (including newline) except a or b or c
[a-q] Lowercase letter between a and q
[A-Q] Uppercase letter between A and Q
[0-7] Digit between 0 and 7
 
String matching Comments
\1, \2, \3, etc. Match strings in captured groups (...). (\n[^\n]+)\1 matches identical adjacent lines; $1 will replace with a single copy.
\k<name> Match strings in named captured groups (?<name>...).
Back references Comments
(sam) (max) (pete) $1 - returns sam
(sam) (max) (pete) $2 - returns max
(sam) (max) (pete) $3 - returns pete
(A) (B) (C) (D) (E) (F) (G) (H) (I) (J) $10 - returns J
(A) (B) (C) (D) (E) (F) (G) (H) (I) (J) ${1}0 - returns A0
 
Extension notation Comments
(?:...) non-capturing parens (?:abc) match and consume, but don't capture, abc
(?=...) positive lookahead, no string consumed abc(?=xyz) matches abc only if followed by xyz
(?!...) negative lookahead, no string consumed abc(?!xyz) matches abc except when it's followed by xyz
(?<=...) positive lookbehind, no string consumed (?<=xyz)abc matches abc only if preceded by xyz
(?<!...) negative lookbehind, no string consumed (?<!xyz)abc matches abc except when it's preceded by xyz
(?<name>...) gives a name to a capture group (?<year>\s\d{4}\s) matches 2016 if surrounded by white space characters Backreference the named group using ${year}
(?#...) comment (?#Just a comment in here)
 
Sample Patterns
Regex pattern Will Match Comments
([A-Za-z0-9-]+) 1 or more characters which are letters, numbers and hyphens
(\d{1,2}\/\d{1,2}\/\d{4}) Date 3/24/2008 or 03/24/2008 or 24/03/2008
\[\[\d{4}\]\] 4 digit number wiki link [[۲۰۰۸ (میلادی)]]
 
 
 


پیوندهای مفید برای کمک و راهنمایی ویرایش

پانویس ویرایش