Regular Expressions: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
You can test regular expressions online at [https://regex101.com/]. | You can test regular expressions online at [https://regex101.com/]. | ||
==Syntax== | |||
===Letters=== | |||
<code>[a-zA-Z]</code> | |||
===Numbers=== | |||
You should match numbers using <code>[0-9]</code>.<br> | |||
<code>\d</code> will match unicode characters which are classified as digits.<br> | |||
See [https://stackoverflow.com/questions/890686/should-i-use-d-or-0-9-to-match-digits-in-a-perl-regex \d vs 0-9] | |||
==Useful Regular Expressions== | ==Useful Regular Expressions== | ||
Line 16: | Line 24: | ||
Capturing significand and exponent separately. | Capturing significand and exponent separately. | ||
<syntaxhighlight lang="ragel"> | <syntaxhighlight lang="ragel"> | ||
([-+]? | ([-+]?[0-9]*\.?[0-9]+)(?:[eE]([-+]?[0-9]+))? | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Capturing the entire string together. | Capturing the entire string together. | ||
<syntaxhighlight lang="ragel"> | <syntaxhighlight lang="ragel"> | ||
([-+]? | ([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?) | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 18:15, 20 December 2019
Regular expressions are used for matching text.
You can test regular expressions online at [1].
Syntax
Letters
[a-zA-Z]
Numbers
You should match numbers using [0-9]
.
\d
will match unicode characters which are classified as digits.
See \d vs 0-9
Useful Regular Expressions
Mostly copied from Regex DB.
Floating Point Number
Without matching scientific notation (e.g. 1.5e-6). Reference
[-+]?[0-9]*\.?[0-9]+
With matching scientific notation (e.g. 1.5e-6).
Reference
Capturing significand and exponent separately.
([-+]?[0-9]*\.?[0-9]+)(?:[eE]([-+]?[0-9]+))?
Capturing the entire string together.
([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?)