Skip to content

Predefined character class replacement inside square brackets is incorrect #54

@HawkSK

Description

@HawkSK

Generex currently replaces predefined character classes while wrapping them in square brackets: \d becomes [0-9]
However, if the \d is already in a character class expression then [\d] becomes [[0-9]], which is compilable correctly by java.util.regex.Pattern but not by dk.brics.automaton.Automaton used by Generex.
Simple regex replacement is apparently not enough, it looks like contextual replacement is needed (tracking if \d is inside [..] char by char, tracking already escaped \)

Input: [\d] (Java String literal "[\\d]")

Expected output:

  • transformed regex [0-9]
  • all matched strings:
0
1
2
3
4
5
6
7
8
9

Actual output:

  • transformed regex [[0-9]]
  • all matched strings:
0]
1]
2]
3]
4]
5]
6]
7]
8]
9]
[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions