Documentation ¶
Overview ¶
nolint: funlen // Complex patterns.
Index ¶
- type CharsBaseDialect
- func (CharsBaseDialect) ASCII() ClassToken
- func (CharsBaseDialect) ASCIIWordBoundary() ClassToken
- func (CharsBaseDialect) Alphabetic() ClassToken
- func (CharsBaseDialect) Alphanumeric() ClassToken
- func (CharsBaseDialect) Any() ClassToken
- func (CharsBaseDialect) Begin() ClassToken
- func (CharsBaseDialect) BeginOfText() ClassToken
- func (CharsBaseDialect) Blank() ClassToken
- func (CharsBaseDialect) Control() ClassToken
- func (CharsBaseDialect) Digits() ClassToken
- func (CharsBaseDialect) End() ClassToken
- func (CharsBaseDialect) EndOfText() ClassToken
- func (CharsBaseDialect) Graphical() ClassToken
- func (CharsBaseDialect) HexDigits() ClassToken
- func (CharsBaseDialect) Lower() ClassToken
- func (CharsBaseDialect) NotASCIIWordBoundary() ClassToken
- func (CharsBaseDialect) Printable() ClassToken
- func (CharsBaseDialect) Punctuation() ClassToken
- func (CharsBaseDialect) Range(from rune, to rune) ClassToken
- func (CharsBaseDialect) Runes(val string) ClassToken
- func (CharsBaseDialect) Single(r rune) ClassToken
- func (d CharsBaseDialect) Unicode(table *unicode.RangeTable) ClassToken
- func (CharsBaseDialect) UnicodeByName(name string) ClassToken
- func (CharsBaseDialect) Upper() ClassToken
- func (CharsBaseDialect) Whitespace() ClassToken
- func (CharsBaseDialect) WordCharacter() ClassToken
- type ClassToken
- type CommonBaseDialect
- func (CommonBaseDialect) Class(tokens ...dialect.ClassToken) ClassToken
- func (CommonBaseDialect) NotClass(tokens ...dialect.ClassToken) ClassToken
- func (CommonBaseDialect) Raw(raw string) RawToken
- func (CommonBaseDialect) RawVerbose(raw string) RawToken
- func (CommonBaseDialect) Text(text string) dialect.Token
- type CompositToken
- type GroupBaseDialect
- type GroupToken
- type HelperDialect
- func (h HelperDialect) Email() dialect.Token
- func (HelperDialect) HostnameRFC1123() dialect.Token
- func (HelperDialect) HostnameRFC952() dialect.Token
- func (h HelperDialect) IP() dialect.Token
- func (HelperDialect) IPv4() dialect.Token
- func (h HelperDialect) IPv6() dialect.Token
- func (h HelperDialect) MD5Hex() dialect.Token
- func (h HelperDialect) NumberRange(from int32, to int32) NumberRange
- func (h HelperDialect) Phone() dialect.Token
- func (h HelperDialect) PhoneE123() dialect.Token
- func (HelperDialect) PhoneE164() dialect.Token
- func (HelperDialect) PhoneInternationalE123() dialect.Token
- func (HelperDialect) PhoneNationalE123() dialect.Token
- func (h HelperDialect) SHA1Hex() dialect.Token
- func (h HelperDialect) SHA256Hex() dialect.Token
- type NumberRange
- type RawToken
- type Repetition
- func (r Repetition) Between(from, to int) dialect.Token
- func (r Repetition) BetweenPreferFewer(from, to int) dialect.Token
- func (r Repetition) EqualOrMoreThan(n int) dialect.Token
- func (r Repetition) EqualOrMoreThanPreferFewer(n int) dialect.Token
- func (r Repetition) Exactly(n int) dialect.Token
- func (r Repetition) OneOrMore() dialect.Token
- func (r Repetition) OneOrMorePreferFewer() dialect.Token
- func (r Repetition) WriteTo(w dialect.StringByteWriter) (n int, err error)
- func (r Repetition) ZeroOrMore() dialect.Token
- func (r Repetition) ZeroOrMorePreferFewer() dialect.Token
- func (r Repetition) ZeroOrOne() dialect.Token
- func (r Repetition) ZeroOrOnePreferZero() dialect.Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CharsBaseDialect ¶
CharsBaseDialect is a namespace that contains common character classes tokens.
Use the alias `rex.Chars`.
const Chars CharsBaseDialect = "CharsBaseDialect"
Chars contains character class elements.
func (CharsBaseDialect) ASCII ¶
func (CharsBaseDialect) ASCII() ClassToken
ASCII only characters. It is an alias to [\x00-\x7F].
Regex: `[[:ascii:]]`.
func (CharsBaseDialect) ASCIIWordBoundary ¶ added in v0.4.0
func (CharsBaseDialect) ASCIIWordBoundary() ClassToken
A word boundary for ACII words. Following positions count as word boundaries:
- Beginning of string: If the first character is an ASCII word character.
- End of string: If the last character is an ASCII word character.
- Between a word and a non-word character.
Regex: `\b`.
func (CharsBaseDialect) Alphabetic ¶
func (CharsBaseDialect) Alphabetic() ClassToken
Alphabetic specifies alphabetic lowercased and uppercased characters. It is an alias to [A-Za-z]. ASCII.
Regex: `[[:alpha:]]`.
func (CharsBaseDialect) Alphanumeric ¶
func (CharsBaseDialect) Alphanumeric() ClassToken
Alphanumeric specifies digits and alphabetic characters. It is an alias to [0-9A-Za-z]. ASCII.
Regex: `[[:alnum:]]`.
func (CharsBaseDialect) Any ¶
func (CharsBaseDialect) Any() ClassToken
Any character, possibly including newline if the flag AnyIncludeNewLine() is set.
Regex: `.`.
func (CharsBaseDialect) Begin ¶
func (CharsBaseDialect) Begin() ClassToken
Begin of text by default or line if the flag EnableMultiline is set.
Regex: `^`.
func (CharsBaseDialect) BeginOfText ¶ added in v0.4.0
func (CharsBaseDialect) BeginOfText() ClassToken
Begin of text (even if the flag EnableMultiline is set)
Regex: `\A`.
func (CharsBaseDialect) Blank ¶
func (CharsBaseDialect) Blank() ClassToken
Blank ASCII characters. It is an alias to [\t ].
Regex: `[[:blank:]]`.
func (CharsBaseDialect) Control ¶
func (CharsBaseDialect) Control() ClassToken
Control characters. It is an alias to [\x00-\x1F\x7F]. ASCII.
Regex: `[[:cntrl:]]`.
func (CharsBaseDialect) Digits ¶
func (CharsBaseDialect) Digits() ClassToken
Digits is an alias to [0-9]. ASCII.
Regex: `\d`.
func (CharsBaseDialect) End ¶
func (CharsBaseDialect) End() ClassToken
End of text or line if the flag EnableMultiline is set.
Regex: `$`.
func (CharsBaseDialect) EndOfText ¶ added in v0.4.0
func (CharsBaseDialect) EndOfText() ClassToken
End of text (even if the flag EnableMultiline is set).
Regex: `\z`.
func (CharsBaseDialect) Graphical ¶
func (CharsBaseDialect) Graphical() ClassToken
Graphical characters. ASCII. It is an alias to [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~].
Regex: `[[:graph:]]`.
func (CharsBaseDialect) HexDigits ¶
func (CharsBaseDialect) HexDigits() ClassToken
HexDigits ASCII characters. It is an alias to [0-9A-Fa-f].
Regex: `[[:xdigit:]]`.
func (CharsBaseDialect) Lower ¶
func (CharsBaseDialect) Lower() ClassToken
Lower cased ASCII characters. It is an alias to [a-z].
Regex: `[[:lower:]]`.
func (CharsBaseDialect) NotASCIIWordBoundary ¶ added in v0.4.0
func (CharsBaseDialect) NotASCIIWordBoundary() ClassToken
A non-word boundary: A position between two word characters or two non-word characters.
Regex: `\B`.
func (CharsBaseDialect) Printable ¶
func (CharsBaseDialect) Printable() ClassToken
Printable ASCII characters. It is an alias to [ [:graph:]].
Regex: `[[:print:]]`.
func (CharsBaseDialect) Punctuation ¶
func (CharsBaseDialect) Punctuation() ClassToken
Punctuation ASCII characters. It is an alias to [!-/:-@[-`{-~].
Regex: `[[:punct:]]`.
func (CharsBaseDialect) Range ¶
func (CharsBaseDialect) Range(from rune, to rune) ClassToken
Range of characters. The input is not validated.
Regex: `[a-z]`.
func (CharsBaseDialect) Runes ¶
func (CharsBaseDialect) Runes(val string) ClassToken
Runes create a class that contains defined runes. It is safe to pass unicode characters.
Example usage:
Runes("a") // == Chars.Single('a') Runes("ab") // == Common.Class(Chars.Single('a'), Chars.Single('b'))
Regex: `[abc]`.
func (CharsBaseDialect) Single ¶
func (CharsBaseDialect) Single(r rune) ClassToken
Single character. It supports not ascii characters. The input is not validated.
Regex: `r`, `\\xHEX_CODE`, or `\\x{HEX_CODE}`.
func (CharsBaseDialect) Unicode ¶
func (d CharsBaseDialect) Unicode(table *unicode.RangeTable) ClassToken
Unicode class. It supports *unicode.RangeTable that is defined in `unicode.Categories` or `unicode.Scripts`. The input is not validated.
Example usage:
Chars.Unicode(unicode.Greek)
Regex: `\p{Greek}`.
func (CharsBaseDialect) UnicodeByName ¶
func (CharsBaseDialect) UnicodeByName(name string) ClassToken
UnicodeByName class. It is alternative to Chars.Unicode, but accepts name of the RangeTable. Unicode character classes are those in unicode.Categories and unicode.Scripts. The input is not validated.
Example usage:
Chars.UnicodeByName("Greek")
Regex: `\p{Greek}`.
func (CharsBaseDialect) Upper ¶
func (CharsBaseDialect) Upper() ClassToken
Upper case ASCII characters. It is an alias to [A-Z].
Regex: `[[:upper:]]`.
func (CharsBaseDialect) Whitespace ¶
func (CharsBaseDialect) Whitespace() ClassToken
Whitespace specfies blank characters. It is an alias to [\t\n\f\r ]. ASCII.
Regex: `\s`.
func (CharsBaseDialect) WordCharacter ¶
func (CharsBaseDialect) WordCharacter() ClassToken
WordCharacter is an alias to [0-9A-Za-z_]. ASCII.
Regex: `\w`.
type ClassToken ¶
type ClassToken struct {
// contains filtered or unexported fields
}
ClassToken helps to specify class tokens.
func (ClassToken) Unwrap ¶
func (ct ClassToken) Unwrap() dialect.ClassToken
Unwrap implements dialect.ClassToken.
func (ClassToken) WriteTo ¶
func (ct ClassToken) WriteTo(w dialect.StringByteWriter) (n int, err error)
WriteTo implements dialect.Token interface.
type CommonBaseDialect ¶
CommonBaseDialect is a namespace that contains common operations.
Use the alias `rex.Common`.
const Common CommonBaseDialect = "CommonBaseDialect"
Common contains base regular expression helpers.
func (CommonBaseDialect) Class ¶
func (CommonBaseDialect) Class(tokens ...dialect.ClassToken) ClassToken
Class specifies the class of characters.
func (CommonBaseDialect) NotClass ¶
func (CommonBaseDialect) NotClass(tokens ...dialect.ClassToken) ClassToken
NotClass specifies the class of characters that should be excluded.
func (CommonBaseDialect) Raw ¶
func (CommonBaseDialect) Raw(raw string) RawToken
Raw appends regular expression as is.
func (CommonBaseDialect) RawVerbose ¶ added in v0.3.0
func (CommonBaseDialect) RawVerbose(raw string) RawToken
RawVerbose appends regular expression and removes comments, spaces and new lines.
When a line contains a # that is not in a character class and is not preceded by an unescaped backslash, all characters from the leftmost such # through the end of the line are ignored.
Leading and trailling whitespaces are ignored.
It also ignores all new lines.
type CompositToken ¶
type CompositToken struct {
// contains filtered or unexported fields
}
CompositToken defines multiple possible expression patterns. It can be described as T1 or T2 or T3, ...
func (CompositToken) WriteTo ¶
func (ct CompositToken) WriteTo(w dialect.StringByteWriter) (n int, err error)
WriteTo implements dialect.Token interface.
type GroupBaseDialect ¶
GroupBaseDialect is a namespace that contains group helpers.
Use the alias `rex.Group`.
const Group GroupBaseDialect = "GroupBaseDialect"
Group helps to define groups.
func (GroupBaseDialect) Composite ¶
func (GroupBaseDialect) Composite(tokens ...dialect.Token) GroupToken
Composite defines logical "OR" between tokens. It can be used for matching one of given expression. It creates non-captured group.
func (GroupBaseDialect) Define ¶
func (GroupBaseDialect) Define(tokens ...dialect.Token) GroupToken
Define a group with ranges of expressions.
func (GroupBaseDialect) NonCaptured ¶ added in v0.2.0
func (g GroupBaseDialect) NonCaptured(tokens ...dialect.Token) GroupToken
NonCaptured defines a group as a non-captured. It is a synonym to Group.Define(...).NonCaptured().
type GroupToken ¶
type GroupToken struct {
// contains filtered or unexported fields
}
GroupToken defines a token that wraps a range of tokens with a `(...)`.
func (GroupToken) NonCaptured ¶
func (gt GroupToken) NonCaptured() GroupToken
NonCaptured marks group as non-captured. It means that this group will not be included in group submatch results. Use this for optimizing regular expressions if you don't need captured result.
It overrides name if set.
func (GroupToken) WithName ¶
func (gt GroupToken) WithName(name string) GroupToken
WithName add a name to captured group.
It overrides non-captured if set.
func (GroupToken) WriteTo ¶
func (gt GroupToken) WriteTo(w dialect.StringByteWriter) (n int, err error)
WriteTo implements dialect.Token interface.
type HelperDialect ¶
HelperDialect is a namespace that contains common patterns.
Use the alias `rex.Helper`.
const Helper HelperDialect = "HelperDialect"
Helper contains common patterns.
func (HelperDialect) Email ¶
func (h HelperDialect) Email() dialect.Token
Email is a pattern, that checks <local_part>@<host_name>.
Hostname is validated considering RFC-1123.
Localpart is unquoted, and may use any of these ASCII characters:
- uppercase and lowercase Latin letters A to Z and a to z, digits 0 to 9
- printable characters !#$%&'*+-/=?^_`{|}~
- dot ., provided that it is not the first or last character and provided also that it does not appear consecutively (e.g., John..Doe@example.com is not allowed).
func (HelperDialect) HostnameRFC1123 ¶
func (HelperDialect) HostnameRFC1123() dialect.Token
HostnameRFC1123 is a pattern like HostnameRFC952, but the restriction on the first character is relaxed to allow either a letter or a digit. Host software must handle host names of up to 63 characters.
func (HelperDialect) HostnameRFC952 ¶
func (HelperDialect) HostnameRFC952() dialect.Token
HostnameRFC952 is a pattern for a text string drawn from the alphabet (A-Z), digits (0-9), minus sign (-), and period (.). Periods are only allowed when they serve to delimit components of "domain style names". No blank or space characters are permitted as part of a name. No distinction is made between upper and lower case. The first character must be an alpha character. The last character must not be a minus sign or period.
func (HelperDialect) IP ¶
func (h HelperDialect) IP() dialect.Token
IP is a pattern for IPv4 or IPv6.
func (HelperDialect) IPv4 ¶
func (HelperDialect) IPv4() dialect.Token
IPv4 is a pattern for an IPv4 address that has the following format: x.x.x.x where x is called an octet and must be a decimal value between 0 and 255.
Example: 127.0.0.1.
func (HelperDialect) IPv6 ¶
func (h HelperDialect) IPv6() dialect.Token
IPv6 is a pattern for IPv6 (Normal) address that has the following format: y:y:y:y:y:y:y:y where y is called a segment and can be any hexadecimal value between 0 and FFFF. The segments are separated by colons - not periods. Zero segments can be skipped. It can also match an IPv6 (Dual) address, that combines an IPv6 and an IPv4.
func (HelperDialect) MD5Hex ¶
func (h HelperDialect) MD5Hex() dialect.Token
MD5Hex is a pattern for a cryptographic hash function MD5 in hex representation.
Example: d41d8cd98f00b204e9800998ecf8427e.
func (HelperDialect) NumberRange ¶ added in v0.2.0
func (h HelperDialect) NumberRange(from int32, to int32) NumberRange
NumberRange helps to define a pattern that matches number ranges. The arguments from and to can have any order or even be equal. Negative numbers are supported.
It doesn't match leading zeros. If you want to match them, use:
Group.NonCaptured( Chars.Single('0').Repeat().ZeroOrMore(), Helper.NumberRange(0, 99), )
func (HelperDialect) Phone ¶
func (h HelperDialect) Phone() dialect.Token
Phone contains composite of different phone patterns: E.164, E.123.
Examples:
+15555555 (607) 123 4567 +22 607 123 4567
func (HelperDialect) PhoneE123 ¶
func (h HelperDialect) PhoneE123() dialect.Token
PhoneE123 is a patter for E.123, it is an international standard by the standardization union (ITU-T), entitled Notation for national and international telephone numbers, e-mail addresses and Web addresses.
It combines international and national formats.
Examples:
(607) 123 4567 +22 607 123 4567
func (HelperDialect) PhoneE164 ¶
func (HelperDialect) PhoneE164() dialect.Token
PhoneE164 is a patter for E.164, that is the international telephone numbering plan that ensures each device on the PSTN has globally unique number. This number allows phone calls and text messages can be correctly routed to individual phones in different countries. E.164 numbers are formatted [+] [country code] [subscriber number including area code] and can have a maximum of fifteen digits.
Example: +15555555.
func (HelperDialect) PhoneInternationalE123 ¶
func (HelperDialect) PhoneInternationalE123() dialect.Token
PhoneInternationalE123 is a patter for telephone number of E.123 international notation.
It matches a 1 to 3 digit country code followed by a space, then 2 to 3 digits, another space, another 2 to 3 digits a final space then 4 digits.
Example: +22 607 123 4567.
func (HelperDialect) PhoneNationalE123 ¶
func (HelperDialect) PhoneNationalE123() dialect.Token
PhoneNationalE123 is a patter for telephone number of E.123 international notation.
It matches the standard national US 3-3-4 number format. A 3 digit area code in brackets, followed by a space, then 3 more digits, followed by another space then 4 digits.
Example: (607) 123 4567.
func (HelperDialect) SHA1Hex ¶
func (h HelperDialect) SHA1Hex() dialect.Token
SHA1Hex is a pattern for a cryptographic hash function SHA1 in hex representation.
Example: da39a3ee5e6b4b0d3255bfef95601890afd80709.
func (HelperDialect) SHA256Hex ¶
func (h HelperDialect) SHA256Hex() dialect.Token
MD5 is a pattern for a cryptographic hash function SHA256 in hex representation.
Example: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.
type NumberRange ¶ added in v0.2.0
type NumberRange struct {
// contains filtered or unexported fields
}
NumberRange helper.
func (NumberRange) WriteTo ¶ added in v0.2.0
func (nr NumberRange) WriteTo(w dialect.StringByteWriter) (n int, err error)
type RawToken ¶
type RawToken struct {
// contains filtered or unexported fields
}
RawToken holds raw regular expression.
func (RawToken) Unwrap ¶
func (rt RawToken) Unwrap() dialect.ClassToken
Unwrap implements dialect.ClassToken.
type Repetition ¶
type Repetition struct {
// contains filtered or unexported fields
}
Repetition helps to add repetition suffix.
func (Repetition) Between ¶
func (r Repetition) Between(from, to int) dialect.Token
Between repeats i=from or i+1 or ... or to, prefer more. It doesn't validate an input.
Regex: `{from,to}`.
func (Repetition) BetweenPreferFewer ¶ added in v0.5.0
func (r Repetition) BetweenPreferFewer(from, to int) dialect.Token
BetweenPreferFewer repeats i=from or i+1 or ... or to, prefer fewer. It doesn't validate an input.
Regex: `{from,to}?`.
func (Repetition) EqualOrMoreThan ¶
func (r Repetition) EqualOrMoreThan(n int) dialect.Token
EqualOrMoreThan repeats i or i+1 or ... or n, prefer more. It doesn't validate an input.
Regex: `{n,}`.
func (Repetition) EqualOrMoreThanPreferFewer ¶ added in v0.5.0
func (r Repetition) EqualOrMoreThanPreferFewer(n int) dialect.Token
EqualOrMoreThanPreferFewer repeats i or i+1 or ... or n, prefer fewer. It doesn't validate an input.
Regex: `{n,}?`.
func (Repetition) Exactly ¶
func (r Repetition) Exactly(n int) dialect.Token
Exactly n times. It doesn't validate an input.
Regex: `{n}`.
func (Repetition) OneOrMore ¶
func (r Repetition) OneOrMore() dialect.Token
OneOrMore repeats one or more, prefer more chars.
Regex: `+`.
func (Repetition) OneOrMorePreferFewer ¶ added in v0.5.0
func (r Repetition) OneOrMorePreferFewer() dialect.Token
OneOrMorePreferFewer repeats one or more, prefer fewer chars.
Regex: `+?`.
func (Repetition) WriteTo ¶
func (r Repetition) WriteTo(w dialect.StringByteWriter) (n int, err error)
WriteTo implements dialect.Token interface.
func (Repetition) ZeroOrMore ¶
func (r Repetition) ZeroOrMore() dialect.Token
ZeroOrMore repeats zero or more, prefer more chars.
Regex: `*`.
func (Repetition) ZeroOrMorePreferFewer ¶ added in v0.5.0
func (r Repetition) ZeroOrMorePreferFewer() dialect.Token
ZeroOrMorePreferFewer repeats zero or more, prefer fewer chars.
Regex: `*?`.
func (Repetition) ZeroOrOne ¶
func (r Repetition) ZeroOrOne() dialect.Token
ZeroOrOne repeats zero or one x, prefer one.
Regex: `?`.
func (Repetition) ZeroOrOnePreferZero ¶ added in v0.5.0
func (r Repetition) ZeroOrOnePreferZero() dialect.Token
ZeroOrOnePreferZero repeats zero or one x, prefer zero.
Regex: `??`.