Match () with regex () (): Difference between revisions
(Created page with "thumb|590x590px The match regex block is a reporter block that matches a string with a regex.") |
Ninja 6734 (talk | contribs) (added page) |
||
Line 1: | Line 1: | ||
=== Information === |
|||
[[File:Block 5 26 2023-3 14 00 PM.png|thumb|590x590px]] |
[[File:Block 5 26 2023-3 14 00 PM.png|thumb|590x590px|alt=match with regex block|match with regex block]] |
||
The match regex block is a reporter block that matches a string with a regex. |
The match regex block is a reporter block that matches a string with a [https://en.wikipedia.org/wiki/Regular_expression 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 ==== |
|||
[[File:MatchWithRegex Example1.png|alt=match with regex: first example|thumb|Example 1]] |
|||
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 ==== |
|||
[[File:MatchWithRegex Example2.png|alt=match with regex: second example|thumb|Example 2]] |
|||
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 [https://en.wikipedia.org/wiki/Regular_expression#Syntax this website]. |
|||
The examples will appear as: [to be matched string] [rule] [third input] -> [result] |
|||
{| class="wikitable mw-collapsible mw-collapsed" |
|||
|+Syntax Table |
|||
!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"] ["a'''b+'''a"] ["g"] -> ["abbbbbba","aba"] |
|||
|- |
|||
|? |
|||
|matches the preceding character or group zero or one times |
|||
|["aba aa abba abbbba"] ["a'''?b'''a"] ["g"] -> ["aba","aa"] |
|||
|- |
|||
|* |
|||
|matches the preceding character or group any amount of times |
|||
|["aba aa abbbbbbbba abbbbbbbbbbbbba"] ["a'''b*'''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"] ["a'''b{3,5}'''a"] ["g"] -> ["abbba","abbbbba"] |
|||
|- |
|||
|{,N} |
|||
|matches the preceding character or group a maximum of N times |
|||
|["aba abbba abbbbba abbbbbbbbbbba"] ["a'''b{,5}'''a"] ["g"] -> ["aba", "abbba", "abbbbba"] |
|||
|- |
|||
|{M,} |
|||
|matches the preceding character or group a minimum of M times |
|||
|["aba abbba abbbbba abbbbbbbbbbba"] ["a'''b{3,}'''a"] ["g"] -> ["abbba", "abbbbba", "abbbbbbbbbbba"] |
|||
|- |
|||
|{N} |
|||
|matches the preceding character or group exactly N times |
|||
|["aba abbba abbbbba abbbbbbbbbbba"] ["a'''b{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 |
|||
|- |
|||
|<nowiki>|</nowiki> |
|||
|seperating possible character or groups |
|||
|["gray grey griy gary"] ["('''<nowiki>gray|grey|griy</nowiki>''')"] ["g"] -> ["gray", "grey", "griy"] |
|||
|- |
|||
|\w |
|||
|syntax for all [https://en.wikipedia.org/wiki/Alphanumericals 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-[https://en.wikipedia.org/wiki/Alphanumericals Alphanumericals] '''not''' (a-z A-Z 0-9 and _) |
|||
|["This is a_text90§!"] ["'''\W'''"] ["g"] -> ["§","!"] |
|||
|} |
Revision as of 18:24, 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"] -> ["§","!"] |