Beta

[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 and target are in range [1,255] (i.e. 1 <= length and length <= 255).
  • Both pattern and target are terminated terminated with \0s.
  • Both pattern and target 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 and Right 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

Regular Expressions
Fundamentals

Similar Kata:

More By Author:

Check out these other kata created by ZED.CWT

Stats:

CreatedFeb 27, 2018
PublishedFeb 27, 2018
Warriors Trained100
Total Skips1
Total Code Submissions14
Total Times Completed3
BF Completions3
Total Stars1
% of votes with a positive feedback rating100% of 2
Total "Very Satisfied" Votes2
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments2
Average Assessed Rank
1 kyu
Highest Assessed Rank
1 kyu
Lowest Assessed Rank
1 kyu
Ad
Contributors
  • ZED.CWT Avatar
Ad