Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any good / interesting analogs to regular expressions in 2d?

Are there any good (or at least interesting but flawed) analogs to regular expressions in two dimensions?

In one dimension I can write something like /aaac?(bc)*b?aaa/ to quickly pull out a region of alternating bs and cs with a border of at least three as. Perhaps as importantly, I can come back a month later and see at a glance what it's looking for.

I'm finding myself writing custom code for analogous problems in 2d (some much more complicated / constrained) and it would be nice to have a more concise and standardized notation, even if I have to write the engine behind it myself.

A second example might be called "find the +". The goal is to locate a column of 3 or more as, a b bracketed by 3 or more as with three or more as below. It should match:

..7...hkj.k f 7...a  h o j  ----a--------  j .a,g- 8 9  .aaabaaaaa7 j  k .a,,g- h j  hh a----?  j     a   hjg  

and might be written as [b^(a{3})v(a{3})>(a{3})<(a{3})] or...

Suggestions?

like image 414
MarkusQ Avatar asked Mar 05 '09 17:03

MarkusQ


People also ask

Which are 3 uses of regular expression?

Regular expressions are useful in any scenario that benefits from full or partial pattern matches on strings. These are some common use cases: verify the structure of strings. extract substrings form structured strings.

Why are regular expressions so complicated?

Density. Regular expressions are dense. This makes them hard to read, but not in proportion to the information they carry. Certainly 100 characters of regular expression syntax is harder to read than 100 consecutive characters of ordinary prose or 100 characters of C code.

What does '*' represent in regular expression?

*$ means - match, from beginning to end, any character that appears zero or more times. Basically, that means - match everything from start to end of the string. This regex pattern is not very useful. Let's take a regex pattern that may be a bit useful.


1 Answers

Not being a regex expert, but finding the problem interesting, I looked around and found this interesting blog entry. Especially the syntax used there for defining the 2D regex looks appealing. The paper linked there might tell you more than me.

Update from comment: Here is the link to the primary author's page where you can download the linked paper "Two-dimensional languages": http://www.mat.uniroma2.it/~giammarr/Research/pubbl.html

like image 153
MicSim Avatar answered Oct 04 '22 01:10

MicSim