rex
rex copied to clipboard
Support flags
Definition
(?flags) set flags within current group; non-capturing
(?flags:re) set flags during re; non-capturing
Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:
i case-insensitive (default false)
m multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
s let . match \n (default false)
U ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
Example methods
rex.Group.Flags(...dialect.GroupFlag) GroupToken // `(?flags)`
type GroupToken struct {
prefix string
tokens ...dialect.Token
}
GroupToken.WithFlags(...base.GroupFlag) dialect.Token // prefix -> `?flags:`
Flag structure
// ab-cd
// means to set `a` and `b`, reset `c` and `d`.
//
// -abc
// reset `a`, `b` and `c`
//
// abc
// set `a`, `b` and `c`
type base.GroupFlag struct {
val rune // i, m, s or U
reset bool
}
rex.Group.FlagCaseInsensitive()
rex.Group.FlagMultiLineMode()
rex.Group.FlagAnyMatchEndLine()
rex.Group.FlagUngreedy()
// WithReset() can be used for any flag.
rex.Group.FlagUngreedy().WithReset()