Difference between revisions of "Regular Expressions"

From rbachwiki
Jump to navigation Jump to search
(Created page with "==Regular Expression== '''literal value''' /my/ #myfile #amy #ammy ===Matches any character === . === Character Classes=== matches [abc] can be used to match any specific...")
 
 
Line 10: Line 10:
matches [abc] can be used to match any specific set of characters
matches [abc] can be used to match any specific set of characters


'''negate when its in the bracket'''
''' ^ Negate when its in the bracket'''
  [^eo]
  [^eo]
  ^ # beginning of the line
  ^ # beginning of the line
  $ # end of the line
  $ # end of the line
===Ranges===
[1-9]
[a-e]
'''Combine ranges'''
[abc123] is the same as [a-c1-3]
<pre>
abc… Letters
123… Digits
\d Any Digit
\D Any Non-digit character
. Any Character
\. Period
[abc] Only a, b, or c
[^abc] Not a, b, nor c
[a-z] Characters a to z
[0-9] Numbers 0 to 9
\w Any Alphanumeric character
\W Any Non-alphanumeric character
{m} m Repetitions
{m,n} m to n Repetitions
* Zero or more repetitions
+ One or more repetitions
? Optional character
\s Any Whitespace
\S Any Non-whitespace character
^…$ Starts and ends
(…) Capture Group
(a(bc)) Capture Sub-group
(.*) Capture all
(abc|def) Matches abc or def
</pre>

Latest revision as of 00:42, 3 April 2019

Regular Expression

literal value

/my/
#myfile
#amy
#ammy

Matches any character

.

Character Classes

matches [abc] can be used to match any specific set of characters

^ Negate when its in the bracket

[^eo]
^ # beginning of the line
$ # end of the line

Ranges

[1-9]
[a-e]

Combine ranges

[abc123] is the same as [a-c1-3]
abc…	Letters
123…	Digits
\d	Any Digit
\D	Any Non-digit character
.	Any Character
\.	Period
[abc]	Only a, b, or c
[^abc]	Not a, b, nor c
[a-z]	Characters a to z
[0-9]	Numbers 0 to 9
\w	Any Alphanumeric character
\W	Any Non-alphanumeric character
{m}	m Repetitions
{m,n}	m to n Repetitions
*	Zero or more repetitions
+	One or more repetitions
?	Optional character
\s	Any Whitespace
\S	Any Non-whitespace character
^…$	Starts and ends
(…)	Capture Group
(a(bc))	Capture Sub-group
(.*)	Capture all
(abc|def)	Matches abc or def