Match () with regex () (): Difference between revisions

Content deleted Content added
added page
mNo edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1:
{{Infobox Block|block_name=match [foo bar] with regex [foo] [g]::operators reporter|block_type=Reporter Block|category=[[Operators]]}}
=== Information ===
The match regex block is a reporter block that matches a string with a [https[w://en.wikipedia.org/wiki/Regular_expressionRegular expressions|regular expression]], a regex.
[[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 [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 ?flag (pleasemore addinfo whatlater this input box doeson)
 
=== Examples ===
 
==== Foo bar example ====
<scratchblocks>
[[File:MatchWithRegex Example1.png|alt=match with regex: first example|thumb|Example 1]]
(match [foo bar] with regex [foo] [g] :: operators) // ["foo"]
</scratchblocks>
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 ====
<scratchblocks>
[[File:MatchWithRegex Example2.png|alt=match with regex: second example|thumb|Example 2]]
(match [banana orange apple banana banana pear apple] with regex [banana] [g] :: operators) // ["banana","banana","banana"]
</scratchblocks>
For this example the block searches for every occurance of the word "banana" which results in the array ["banana","banana","banana"].
 
== See Also ==
=== 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].
 
* [[Regular expressions]]
The examples will appear as: [to be matched string] [rule] [third input] -> [result]
{{Blockcat|type=Reporter|cat=Operators}}
{| 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"] -> ["§","!"]
|}