[BF] Simple Regular Expression Matcher
Description:
Background
Regular Expression, a widely used concept in the category of pattern matching. Despite the normal usage of it, people always have fun with it (RegexGolf, RegexCrossword, etc..).
Here, let's have fun with it in BF!
Requirment
You are given a variant length pattern
and a variant length target
string.
And are going to output
- Nothing. If there are no matches.
- Or the range of matched substring, output as ascii characters.
Where
- Lengths of both
pattern
andtarget
are in range [1,255] (i.e. 1 <= length and length <= 255). - Both
pattern
andtarget
are terminated terminated with\0
s. - Both
pattern
andtarget
are constructed using ONLY characters from!
(ascii code: 33) to~
(ascii code 126) inclusive. - The input would be formatted like
PATTERN\0TARGET\0
. - indexes start at 0.
- The output range should only contains two characters
Left
andRight
where matched substring is in range[Left,Right)
(i.e.Left
is the index of the left most character,Right
is the index of the right most character PLUS ONE). - If there are multiple possible matches, output the one with MINIMUM
Left
value. - The strategy of matching is GREEDY, so if there are still multiple possible matches, output the one with MAXIMUM
Right
value.
About Patterns
Patterns here only use two concepts from Regular Expression, .
and *
.
Where
.
matches any characters.*
indicates zero or more occurrences of the preceding element.
Other special characters you may be familiar with such as ?
, ^
and $
are just matching itself without special effect.
Also, the patterns here do NOT do escaping, which means \
has no special effect.
The given patterns are all valid, which means the following cases would never occur.
*xx
x**
Because backtracking would be a nightmare of performance, all patterns would contain NOT MORE THAN FOUR *
s.
Example
Pattern: a.b
Target: cdacaebef
Input as: a.b\0cdacaebef\0
Matched: aeb
, index 4
Expected range: [4,7)
Pattern: cd*e
Target: cddf
Input as: cd*e\0cddf\0
Matched: Nothing
Expected result: An empty string
Code size limit
To disable a roughly generated BF code, there should be a limit of code size.
The size of BF code transpiled from my own tool is 17807
, after optimization, the size become 3406
.
Using a FAIR dice to pick a number between 3406 and 17807, i set the limit at 4399
.
Dont worry if comments or formatting your code would cause exceeding the limit, all characters expcept the 8 operators would be removed, and comment block in the begining would be removed.
eg.
Before removing.
[
comment
] without any operators [
another comment
[ nested ]
] > with < some operators > [
do something
] ++--
After removed.
><>[]++--
Have Fun. O_o
Similar Kata:
Stats:
Created | Feb 27, 2018 |
Published | Feb 27, 2018 |
Warriors Trained | 100 |
Total Skips | 1 |
Total Code Submissions | 14 |
Total Times Completed | 3 |
BF Completions | 3 |
Total Stars | 1 |
% of votes with a positive feedback rating | 100% of 2 |
Total "Very Satisfied" Votes | 2 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 2 |
Average Assessed Rank | 1 kyu |
Highest Assessed Rank | 1 kyu |
Lowest Assessed Rank | 1 kyu |