Difference between revisions of "Template:LSL Regular Expressions"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{{!}} class="notsortable" {{Prettytable|style=margin-top:0;}} {{!}}- ! colspan=3|Wildcard |- ! . | Matches any character | |- ! colspan=3|Anchors |- ! ^ | Matches the begin...")
 
Line 55: Line 55:
! [''abc'']
! [''abc'']
| Matches any one of the enumerated characters.
| Matches any one of the enumerated characters.
|
|-
! [''a''-''c'']
| Matches any character in the specified range.
|
|
|-
|-
! [^''abc'']
! [^''abc'']
| Matches any character other than the enumerated characters.
| Matches any character other than the enumerated characters.
|
|-
! <nowiki>[[:</nowiki>''name'':]]
| Matches any character of the named class.
|
|
|-
|-
! [''a''-''c'']
!
| Matches any character in the specified range.
| Any of the above character set definitions may be combined.
|
|-
! colspan=3|Escape Sequences
|-
|
| colspan=2|'''Specific Characters'''
|-
! \e
| colspan=2| ASCII 0x1B, ESC
|-
! \n
| colspan=2| New line
|-
! \r
| colspan=2| Carriage return
|-
! \t
| colspan=2| Tab
|-
! \x''dd''
| colspan=2| Matches an ASCII character with the code ''dd''
|-
|
| colspan=2|'''Single character classes'''
|-
! \d
 
\D
| Any decimal digit.
| '''\d''' is equivalent to <nowiki>[[</nowiki>:digit:]] or [0-9]
 
'''\D''' is equivalent to <nowiki>[^[</nowiki>:digit:]] or [^0-9]
|-
! \l
 
\L
| Any lower case character.
| '''\l''' is equivalent to <nowiki>[[</nowiki>:lower:]] or [a-z]
 
'''\L''' is equivalent to <nowiki>[^[</nowiki>:lower:]] or [^a-z]
|-
! \s
 
\S
| Any whitespace character.
| '''\s''' is equivalent to <nowiki>[[</nowiki>:space:]] or [ \t\r\n]
 
'''\S''' is equivalent to <nowiki>[^[</nowiki>:space:]] or [^ \t\r\n]
|-
! \u
 
\U
| Any upper case character.
| '''\u''' is equivalent to <nowiki>[[</nowiki>:upper:]] or [A-Z]
 
'''\U''' is equivalent to <nowiki>[^[</nowiki>:upper:]] or [^A-Z]
|-
! \w
 
\W
| Any "word" character.
 
Alphanumeric plus underscore
| '''\w''' is equivalent to <nowiki>[[</nowiki>:upper:][:lower:][:digit:]_] or [A-Za-z0-9_]
 
'''\W''' is equivalent to <nowiki>[^[</nowiki>:upper:][:lower:][:digit:]_] or [^A-Za-z0-9_]
|-
|
|
| colspan=2|'''Word boundaries'''
|-
! \<
| Start of word.
|-
! \>
| End of word
|-
! \b
|
|-
! \B
| Not a word boundary.
|-
! colspan=3|Named Character Classes
|-
! alnum
| Any alpha-numeric character.
|
* <nowiki>[[</nowiki>:alnum:]] &rarr; [0-9a-zA-Z]
* <nowiki>[^[</nowiki>:alnum:]] &rarr; [^0-9a-zA-Z]
|-
! alpha
| Any alphabetic character.
|
* <nowiki>[[</nowiki>:alpha:]] &rarr; [a-zA-Z]
* <nowiki>[^[</nowiki>:alpha:]] &rarr; [^a-zA-Z]
|-
! blank
| Any whitespace character that is not a line separator.
|-
! cntrl
| Any control character
|
* <nowiki>[[</nowiki>:cntrl:]] &rarr; [\x01-\x31]
* <nowiki>[^[</nowiki>:cntrl:]] &rarr; [^\x01-\x31]
|-
! digit
d
| Any decimal digit
|
* <nowiki>[[</nowiki>:digit:]] &rarr; [0-9]
* <nowiki>[^[</nowiki>:digit:]] &rarr; [^0-9]
|-
! lower
l
| Any lower case character.
|
* <nowiki>[[</nowiki>:lower:]] &rarr; [a-z]
* <nowiki>[^[</nowiki>:lower:]] &rarr; [^a-z]
|-
! print
| Any printable character.
|-
! punct
| Any punctiation character.
|-
! space
s
| Any whitespace character.
|-
! upper
u
| Any upper case character.
|
* <nowiki>[[</nowiki>:upper:]] &rarr; [A-Z]
* <nowiki>[^[</nowiki>:upper:]] &rarr; [^A-Z]
|-
! word
w
| Any control character
|
* <nowiki>[[</nowiki>:word:]] &rarr; [0-9a-zA-Z_]
* <nowiki>[^[</nowiki>:word:]] &rarr; [^0-9a-zA-Z_]
|-
! xdigit
w
| Any hexadecimal digit character
|
* <nowiki>[[</nowiki>:xdigit:]] &rarr; [0-9a-fA-F]
* <nowiki>[^[</nowiki>:xdigit:]] &rarr; [^0-9a-fA-F]
|}
|}

Revision as of 14:18, 19 October 2022

Wildcard
. Matches any character
Anchors
^ Matches the beginning of the string.
$ Matches the end of the string.
Repeats
* Matches the preceding atom 0 or more times.
+ Matches the preceding atom 1 or more times.
? Matches the preceding atom 0 or 1 times.
{n}

{n,}

{n, m}

Matches the preceding atom n, n or more, or between n and m times.
Sub-expressions
(expression) Text enclosed in parentheses is a marked sub-expression. Text matched as part of a sub-expressions is split out and may be repeated.
Alternation
a | b Match either a or b.
Character Sets
[abc] Matches any one of the enumerated characters.
[a-c] Matches any character in the specified range.
[^abc] Matches any character other than the enumerated characters.
[[:name:]] Matches any character of the named class.
Any of the above character set definitions may be combined.
Escape Sequences
Specific Characters
\e ASCII 0x1B, ESC
\n New line
\r Carriage return
\t Tab
\xdd Matches an ASCII character with the code dd
Single character classes
\d

\D

Any decimal digit. \d is equivalent to [[:digit:]] or [0-9]

\D is equivalent to [^[:digit:]] or [^0-9]

\l

\L

Any lower case character. \l is equivalent to [[:lower:]] or [a-z]

\L is equivalent to [^[:lower:]] or [^a-z]

\s

\S

Any whitespace character. \s is equivalent to [[:space:]] or [ \t\r\n]

\S is equivalent to [^[:space:]] or [^ \t\r\n]

\u

\U

Any upper case character. \u is equivalent to [[:upper:]] or [A-Z]

\U is equivalent to [^[:upper:]] or [^A-Z]

\w

\W

Any "word" character.

Alphanumeric plus underscore

\w is equivalent to [[:upper:][:lower:][:digit:]_] or [A-Za-z0-9_]

\W is equivalent to [^[:upper:][:lower:][:digit:]_] or [^A-Za-z0-9_]

Word boundaries
\< Start of word.
\> End of word
\b
\B Not a word boundary.
Named Character Classes
alnum Any alpha-numeric character.
  • [[:alnum:]] → [0-9a-zA-Z]
  • [^[:alnum:]] → [^0-9a-zA-Z]
alpha Any alphabetic character.
  • [[:alpha:]] → [a-zA-Z]
  • [^[:alpha:]] → [^a-zA-Z]
blank Any whitespace character that is not a line separator.
cntrl Any control character
  • [[:cntrl:]] → [\x01-\x31]
  • [^[:cntrl:]] → [^\x01-\x31]
digit

d

Any decimal digit
  • [[:digit:]] → [0-9]
  • [^[:digit:]] → [^0-9]
lower

l

Any lower case character.
  • [[:lower:]] → [a-z]
  • [^[:lower:]] → [^a-z]
print Any printable character.
punct Any punctiation character.
space

s

Any whitespace character.
upper

u

Any upper case character.
  • [[:upper:]] → [A-Z]
  • [^[:upper:]] → [^A-Z]
word

w

Any control character
  • [[:word:]] → [0-9a-zA-Z_]
  • [^[:word:]] → [^0-9a-zA-Z_]
xdigit

w

Any hexadecimal digit character
  • [[:xdigit:]] → [0-9a-fA-F]
  • [^[:xdigit:]] → [^0-9a-fA-F]