Regular Expressions: Difference between revisions
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Regular expressions are used for matching text. | Regular expressions are used for matching text.<br> | ||
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 13: | Line 21: | ||
With matching scientific notation (e.g. 1.5e-6). | With matching scientific notation (e.g. 1.5e-6). | ||
[https://rgxdb.com/r/1RSPF8MG Reference] | [https://rgxdb.com/r/1RSPF8MG Reference]<br> | ||
Capturing significand and exponent separately. | |||
<syntaxhighlight lang="ragel"> | <syntaxhighlight lang="ragel"> | ||
([-+]? | ([-+]?[0-9]*\.?[0-9]+)(?:[eE]([-+]?[0-9]+))? | ||
</syntaxhighlight> | |||
Capturing the entire string together. | |||
<syntaxhighlight lang="ragel"> | |||
([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?) | |||
</syntaxhighlight> | </syntaxhighlight> | ||