Match () with regex () (): Difference between revisions
Ninja 6734 (talk | contribs) (New comments) |
Ninja 6734 (talk | contribs) (finished the page) |
||
Line 82: | Line 82: | ||
|syntax for all non-[https://en.wikipedia.org/wiki/Alphanumericals Alphanumericals] '''not''' (a-z A-Z 0-9 and _) |
|syntax for all non-[https://en.wikipedia.org/wiki/Alphanumericals Alphanumericals] '''not''' (a-z A-Z 0-9 and _) |
||
|["This is a_text90§!"] ["'''\W'''"] ["g"] -> ["§","!"] |
|["This is a_text90§!"] ["'''\W'''"] ["g"] -> ["§","!"] |
||
|- |
|||
|\s |
|||
|syntax for the [https://en.wikipedia.org/wiki/Whitespace_character Whitespace] which includes: |
|||
Ascii: tab, space, line feed, form feed and carriage return |
|||
Unicode: matches, no-break spaces, next line, and the variable-width spaces (amongst others). Basically anything that is not visible |
|||
|["This is a testing example"] ["'''\s'''"] ["g"] -> [" "," "," "] |
|||
|- |
|||
|\S |
|||
|syntax for all non-[https://en.wikipedia.org/wiki/Whitespace_character Whitespaces] |
|||
|["This is a tesing example"] ["'''\S'''"] ["g"] -> ["T","h","i","s","i","s","a","t","e","s","t","i","n","g","e","x","a"m","p","l","e"] |
|||
|- |
|||
|\d |
|||
|syntax for all [https://en.wikipedia.org/wiki/Numerical_digit Digits] (0-9) |
|||
|["My favourite number is 917"] ["'''\d'''"] ["g"] -> ["9","1","7"] |
|||
|- |
|||
|\D |
|||
|syntax for all non-[https://en.wikipedia.org/wiki/Numerical_digit Digits] '''not''' (0-9) |
|||
|["9 + 10 = 21"] ["'''\D'''"] ["g"] -> ["+","="] |
|||
|- |
|||
|^ |
|||
|syntax for the beginning of a string or line |
|||
|["Hello World, I say Hello"] ["'''^'''Hello"] ["g"] -> ["Hello"] |
|||
|- |
|||
|$ |
|||
|syntax for the end of a string or line |
|||
|["Hello World, I say Hello"] ["Hello'''$'''"] ["g"] -> ["Hello"] |
|||
|- |
|||
|\A |
|||
|syntax for the beginning of a string but not line |
|||
|["Hello World, |
|||
Hello"] ["'''\A'''"] ["g"] -> ["Hello"] |
|||
|- |
|||
|\z |
|||
|syntax for the end of a string but not line |
|||
|["Hello World, |
|||
Hello"] ["'''\z'''"] ["g"] -> ["Hello"] |
|||
|- |
|||
|[^...] |
|||
|syntax for any character or group '''not''' inside of the rectangular parenthesis |
|||
|["Hello Hallo Hmllo Hkllo"] ["H'''[^ea]'''llo"] ["g"] -> ["Hmllo","Hkllo"]. |
|||
This can also used like this: |
|||
["Hello Hallo Hmllo Hkllo"] ["H'''[^a-k]'''llo"] ["g] -> ["Hmllo"]. |
|||
which acts as every letter but those in the alphabet from a to k |
|||
|- |
|||
|\ |
|||
|syntax for [https://en.wikipedia.org/wiki/Escape_character Escaping Characters]. |
|||
For example used to get the actual character * instead of the syntax |
|||
|["I would like to find all *s in this very *-filled *text"] ["'''\*'''"] ["g"] -> ["*","*","*"] |
|||
This is also used to escape itself: |
|||
["I would like to find all \s in this very \-filled \text"] ["'''\\'''"] ["g"] -> ["\","\","\"] |
|||
|} |
|} |
||
Revision as of 18:59, 8 June 2024
Information
![match with regex block](http://static.miraheze.org/pmodwiki/thumb/9/9a/Block_5_26_2023-3_14_00_PM.png/590px-Block_5_26_2023-3_14_00_PM.png)
The match regex block is a reporter block that matches a string with a regular expression, a regex.
Use
This block searches for every instance of the selected rule. The rule can be inserted into the second input box. The third input box acts as a ? (please add what this input box does)
Examples
Foo bar example
![match with regex: first example](http://static.miraheze.org/pmodwiki/e/e2/MatchWithRegex_Example1.png)
In this example inputs of the block it searches for the string "foo" in the string "foo bar" which will result in the array ["foo"] since there is only one foo in the string.
Fruit example
![match with regex: second example](http://static.miraheze.org/pmodwiki/thumb/c/ce/MatchWithRegex_Example2.png/300px-MatchWithRegex_Example2.png)
For this example the block searches for every occurance of the word "banana" which results in the array ["banana","banana","banana"].
Regular expression rule syntax
The rules of regular expressions have their own syntax which you can all look up on this website.
The examples will appear as: [to be matched string] [rule] [third input] -> [result]
meta characters | Description | Example |
---|---|---|
. | This is the syntax for any character | ["gray grey griy gary"] ["gr.y"] ["g"] -> ["gray", "grey", "griy"] |
() | groups a set of characters | No actual change to the result, will be needed later on |
+ | matches the preceding character or group one or more times | ["abbbbbba aba aa"] ["ab+a"] ["g"] -> ["abbbbbba","aba"] |
? | matches the preceding character or group zero or one times | ["aba aa abba abbbba"] ["a?ba"] ["g"] -> ["aba","aa"] |
* | matches the preceding character or group any amount of times | ["aba aa abbbbbbbba abbbbbbbbbbbbba"] ["ab*a"] ["g"] -> ["aba", "aa", "abbbbbbbba", "abbbbbbbbbbbbba"] |
{M,N} | matches the preceding character or group
a minimum of M to a naximum of N times |
["aba abbba abbbbba abbbbbbbbbbba"] ["ab{3,5}a"] ["g"] -> ["abbba","abbbbba"] |
{,N} | matches the preceding character or group a maximum of N times | ["aba abbba abbbbba abbbbbbbbbbba"] ["ab{,5}a"] ["g"] -> ["aba", "abbba", "abbbbba"] |
{M,} | matches the preceding character or group a minimum of M times | ["aba abbba abbbbba abbbbbbbbbbba"] ["ab{3,}a"] ["g"] -> ["abbba", "abbbbba", "abbbbbbbbbbba"] |
{N} | matches the preceding character or group exactly N times | ["aba abbba abbbbba abbbbbbbbbbba"] ["ab{3}a"] ["g"] -> ["abbba"] |
[...] | syntax for any characters or group within the rectangular parenthesis | ["Hello Hallo Hmllo Hkllo"] ["H[ea]llo"] ["g"] -> ["Hello","Hallo"].
This can also used like this: ["Hello Hallo Hmllo Hkllo"] ["H[a-k]llo"] ["g] -> ["Hello","Hallo", "Hkllo"]. which acts as every letter in the alphabet from a to k |
| | seperating possible character or groups | ["gray grey griy gary"] ["(gray|grey|griy)"] ["g"] -> ["gray", "grey", "griy"] |
\w | syntax for all Alphanumericals (a-z A-Z 0-9 and _) | ["This is a_text90§!"] ["\w"] ["g"] -> ["T","h","i","s","i","s","a","_","t","e","x","t","9","0"] |
\W | syntax for all non-Alphanumericals not (a-z A-Z 0-9 and _) | ["This is a_text90§!"] ["\W"] ["g"] -> ["§","!"] |
\s | syntax for the Whitespace which includes:
Ascii: tab, space, line feed, form feed and carriage return Unicode: matches, no-break spaces, next line, and the variable-width spaces (amongst others). Basically anything that is not visible |
["This is a testing example"] ["\s"] ["g"] -> [" "," "," "] |
\S | syntax for all non-Whitespaces | ["This is a tesing example"] ["\S"] ["g"] -> ["T","h","i","s","i","s","a","t","e","s","t","i","n","g","e","x","a"m","p","l","e"] |
\d | syntax for all Digits (0-9) | ["My favourite number is 917"] ["\d"] ["g"] -> ["9","1","7"] |
\D | syntax for all non-Digits not (0-9) | ["9 + 10 = 21"] ["\D"] ["g"] -> ["+","="] |
^ | syntax for the beginning of a string or line | ["Hello World, I say Hello"] ["^Hello"] ["g"] -> ["Hello"] |
$ | syntax for the end of a string or line | ["Hello World, I say Hello"] ["Hello$"] ["g"] -> ["Hello"] |
\A | syntax for the beginning of a string but not line | ["Hello World,
Hello"] ["\A"] ["g"] -> ["Hello"] |
\z | syntax for the end of a string but not line | ["Hello World,
Hello"] ["\z"] ["g"] -> ["Hello"] |
[^...] | syntax for any character or group not inside of the rectangular parenthesis | ["Hello Hallo Hmllo Hkllo"] ["H[^ea]llo"] ["g"] -> ["Hmllo","Hkllo"].
This can also used like this: ["Hello Hallo Hmllo Hkllo"] ["H[^a-k]llo"] ["g] -> ["Hmllo"]. which acts as every letter but those in the alphabet from a to k |
\ | syntax for Escaping Characters.
For example used to get the actual character * instead of the syntax |
["I would like to find all *s in this very *-filled *text"] ["\*"] ["g"] -> ["*","*","*"]
This is also used to escape itself: ["I would like to find all \s in this very \-filled \text"] ["\\"] ["g"] -> ["\","\","\"] |
Comments
if someone knows what the third input is for please add it here
-- Ninja 6734 (talk) 18:25, 8 June 2024 (UTC)