using_20regular_20expressions
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| using_20regular_20expressions [2018/03/31 13:19] – external edit 127.0.0.1 | using_20regular_20expressions [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| | [abc]\\ | matches " | | [abc]\\ | matches " | ||
| | [a-z]\\ | matches any lowercase letter\\ | | | [a-z]\\ | matches any lowercase letter\\ | | ||
| - | | [^b]at\\ | matches " | + | | < |
| \\ For more information on the syntax of regular expressions see this [[http:// | \\ For more information on the syntax of regular expressions see this [[http:// | ||
| + | <code bb4w> | ||
| SYS " | SYS " | ||
| IF gnu_regex% = 0 ERROR 100, " | IF gnu_regex% = 0 ERROR 100, " | ||
| SYS " | SYS " | ||
| SYS " | SYS " | ||
| + | </ | ||
| For this to work **gnu_regex.dll** needs to be in the current directory, the Windows directory (often C: | For this to work **gnu_regex.dll** needs to be in the current directory, the Windows directory (often C: | ||
| + | <code bb4w> | ||
| SYS " | SYS " | ||
| + | </ | ||
| The code below illustrates a very simple example of setting up a pattern and inputting strings from the user which are tested against this pattern:\\ \\ | The code below illustrates a very simple example of setting up a pattern and inputting strings from the user which are tested against this pattern:\\ \\ | ||
| + | <code bb4w> | ||
| DIM buffer% 255 | DIM buffer% 255 | ||
| Line 26: | Line 31: | ||
| IF result% PRINT "Not matched" | IF result% PRINT "Not matched" | ||
| UNTIL FALSE | UNTIL FALSE | ||
| + | </ | ||
| You should ensure that **buffer%** points to a memory buffer large enough to contain the // | You should ensure that **buffer%** points to a memory buffer large enough to contain the // | ||
| + | <code bb4w> | ||
| DIM offsets{start%, | DIM offsets{start%, | ||
| REPEAT | REPEAT | ||
| Line 33: | Line 40: | ||
| IF result% PRINT "Not matched" | IF result% PRINT "Not matched" | ||
| UNTIL FALSE | UNTIL FALSE | ||
| + | </ | ||
| Here **offsets.start%** is set to the offset from the beginning of the string of the first match.\\ \\ You can specify that the matching is //case insensitive// | Here **offsets.start%** is set to the offset from the beginning of the string of the first match.\\ \\ You can specify that the matching is //case insensitive// | ||
| + | <code bb4w> | ||
| _REG_ICASE = 2 | _REG_ICASE = 2 | ||
| SYS regcomp%, buffer%, pattern$, _REG_ICASE TO result% | SYS regcomp%, buffer%, pattern$, _REG_ICASE TO result% | ||
| + | </ | ||
| You can also specify the use of **extended regular expressions** by setting the final parameter to 1:\\ \\ | You can also specify the use of **extended regular expressions** by setting the final parameter to 1:\\ \\ | ||
| + | <code bb4w> | ||
| _REG_EXTENDED = 1 | _REG_EXTENDED = 1 | ||
| SYS regcomp%, buffer%, pattern$, _REG_EXTENDED TO result% | SYS regcomp%, buffer%, pattern$, _REG_EXTENDED TO result% | ||
| + | </ | ||
| In this mode additional // | In this mode additional // | ||
| - | | abc|def\\ | matches " | + | | < |
| \\ | \\ | ||
| ---- | ---- | ||
| [1] When last checked, the file **gnu_regex.exe** was corrupted (missing the last byte). To repair it you can use this simple BBC BASIC program:\\ \\ | [1] When last checked, the file **gnu_regex.exe** was corrupted (missing the last byte). To repair it you can use this simple BBC BASIC program:\\ \\ | ||
| + | <code bb4w> | ||
| F% = OPENUP(" | F% = OPENUP(" | ||
| PTR#F% = EXT#F% | PTR#F% = EXT#F% | ||
| BPUT #F%,0 | BPUT #F%,0 | ||
| CLOSE #F% | CLOSE #F% | ||
| + | </ | ||
using_20regular_20expressions.1522502389.txt.gz · Last modified: 2024/01/05 00:16 (external edit)