Skip to content

Commit 29e2c9b

Browse files
committed
Update README.md
1 parent 818b630 commit 29e2c9b

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,55 @@ if (matcher.matches() != 0)
327327
std::cout << std::string(matcher[1].first, matcher[1].second) << " was a good year!" << std::endl;
328328
```
329329

330-
To search a string for words `\w+`:
330+
A pattern match made by any of the regex engines to match input with
331+
`matches()`, or search with `find()`, or tokenize with `scan()`, or split with
332+
`split()` includes detailed information that can be retrieved with the
333+
following methods:
334+
335+
- `accept()` returns group capture index (or zero if not captured/matched)
336+
- `text()` returns `const char*` to 0-terminated match (ends in `\0`)
337+
- `strview()`returns `std::string_view` text match (preserves `\0`s) (C++17)
338+
- `str()` returns `std::string` text match (preserves `\0`s)
339+
- `wstr()` returns `std::wstring` wide text match (converted from UTF-8)
340+
- `chr()` returns first 8-bit char of the text match (`str()[0]` as int)
341+
- `wchr()` returns first wide char of the text match (`wstr()[0]` as int)
342+
- `pair()` returns `std::pair<size_t,std::string>(accept(),str())`
343+
- `wpair()` returns `std::pair<size_t,std::wstring>(accept(),wstr())`
344+
- `size()` returns the length of the text match in bytes
345+
- `wsize()` returns the length of the match in number of wide characters
346+
- `lines()` returns the number of lines in the text match (>=1)
347+
- `columns()` returns the number of columns of the text match (>=0)
348+
- `begin()` returns `const char*` to non-0-terminated text match begin
349+
- `end()` returns `const char*` to non-0-terminated text match end
350+
- `rest()` returns `const char*` to 0-terminated rest of input
351+
- `span()` returns `const char*` to 0-terminated match enlarged to span the line
352+
- `line()` returns `std::string` line with the matched text as a substring
353+
- `wline()` returns `std::wstring` line with the matched text as a substring
354+
- `more()` tells the matcher to append the next match (when using `scan()`)
355+
- `less(n)` cuts `text()` to `n` bytes and repositions the matcher
356+
- `lineno()` returns line number of the match, starting at line 1
357+
- `columno()` returns column number of the match in characters, starting at 0
358+
- `lineno_end()` returns ending line number of the match, starting at line 1
359+
- `columno_end()` returns ending column number of the match, starting at 0
360+
- `bol()` returns `const char*` to begin of matching line (not 0-terminated)
361+
- `border()`returns the byte offset from the start of the line of the match
362+
- `first()` returns input position of the first character of the match
363+
- `last()` returns input position + 1 of the last character of the match
364+
- `at_bol()` true if matcher reached the begin of a new line `\n`
365+
- `at_bob()` true if matcher is at the begin of input and no input consumed
366+
- `at_end()` true if matcher is at the end of input
367+
- `[0]` operator returns `std::pair<const char*,size_t>(begin(),size())`
368+
- `[n]` operator returns n'th capture `std::pair<const char*,size_t>`
369+
370+
To search a string for words `\w+` to display with the column number of each
371+
word found:
331372

332373
```{.cpp}
333374
#include <reflex/boostmatcher.h> // reflex::BoostMatcher, reflex::Input, boost::regex
334375
// use a BoostMatcher to search for words in a sentence
335376
reflex::BoostMatcher matcher("\\w+", "How now brown cow.");
336377
while (matcher.find() != 0)
337-
std::cout << "Found " << matcher.text() << std::endl;
378+
std::cout << "Found " << matcher.text() << " at column " << matcher.columno() << std::endl;
338379
```
339380

340381
The `split` method is roughly the inverse of the `find` method and returns text
@@ -449,7 +490,7 @@ License and copyright
449490
---------------------
450491

451492
RE/flex by Robert van Engelen, Genivia Inc.
452-
Copyright (c) 2016-2023, All rights reserved.
493+
Copyright (c) 2016-2025, All rights reserved.
453494

454495
RE/flex is distributed under the BSD-3 license LICENSE.txt.
455496
Use, modification, and distribution are subject to the BSD-3 license.

0 commit comments

Comments
 (0)