DFA (Linear Time) Regular Expression Capture Groups: Possible?

Is it possible to implement capture groups with regular expressions based on DFA, while preserving linear time complexity with respect to the input length?

Intuitively, I think not, because the procedure for constructing the subset does not know which capture group it could land inside, but this is the first time I realized that this could be a potential problem, so I don’t know.

+4
source share
2 answers

Is it possible to implement capture groups with regular expressions based on DFA, while preserving linear time complexity with respect to the input length?

- , . regex /a|(a)/; "a" .

, , , . , , .

, , , , , , , .

, . , , DFA. , , Wikipedia : " ".

, . . , , :

[...] , .

, /ab|(a)c/ /(a[bc])|ad/ . , , .

+3

http://github.com/hoehrmann/demo-parselov . -, ,

X = "a" B "c"
B = "b"

  • start X
  • ""
  • B
  • ""
  • final B
  • ""
  • final X

DFA . 1 2, 3 4, 5 6 , , 7. "abc",

  • {offset: 0, vertices: [1, 2]}
  • {offset: 1, vertices: [3, 4]}
  • {offset: 2, vertices: [5, 6]}
  • {offset: EOF, : [7]}

. , (, ) :

  • (o0, v1) → (o0, v2)
  • (o0, v2) → (o1, v3)
  • (o1, v3) → (o1, v4)
  • ...

, (EOF, v7), O (n) . , . .

0

All Articles