Regular Expressions: Difference between revisions

no edit summary
No edit summary
No edit summary
 
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">
([-+]?\d*\.?\d+)(?:[eE]([-+]?\d+))?
([-+]?[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">
([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)
([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?)
</syntaxhighlight>
</syntaxhighlight>