Copyright 2020 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Exported LRE interface.
package match
import (
)
An LRE is a compiled license regular expression. TODO: Move this comment somewhere non-internal later. A license regular expression (LRE) is a pattern syntax intended for describing large English texts such as software licenses, with minor allowed variations. The pattern syntax and the matching are word-based and case-insensitive; punctuation is ignored in the pattern and in the matched text. The valid LRE patterns are: word - a single case-insensitive word __N__ - any sequence of up to N words expr1 expr2 - concatenation expr1 || expr2 - alternation (( expr )) - grouping expr?? - zero or one instances of expr /* text */ - a comment To make patterns harder to misread in large texts: - || must only appear inside (( )) - ?? must only follow (( )) - (( must be at the start of a line, preceded only by spaces - )) must be at the end of a line, followed only by spaces and ??. For example: /* https://en.wikipedia.org/wiki/Filler_text */ Now is ((not))?? the time for all good ((men || women || people)) to come to the aid of their __1__.
compile initializes lre.dfa. It is invoked lazily (in Match) because most LREs end up only being inputs to a MultiLRE; we never need their DFAs directly.
A Match records the position of a single match in a text.
typeMatchstruct {
IDint// index of LRE in list passed to NewMultiLREStartint// word index of start of matchEndint// word index of end of match
}
Match reports all leftmost-longest, non-overlapping matches in text. It always returns a non-nil *Matches, in order to return the split text. Check len(matches.List) to see whether any matches were found.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.