Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining ^ with | in regex leads to unexpected behavior #450

Closed
koniksedy opened this issue Oct 30, 2024 · 1 comment
Closed

Combining ^ with | in regex leads to unexpected behavior #450

koniksedy opened this issue Oct 30, 2024 · 1 comment
Assignees

Comments

@koniksedy
Copy link
Collaborator

koniksedy commented Oct 30, 2024

When constructing an NFA from a regular expression that combines ^ and |, the resulting automaton can have unexpected languages (only partial or even empty).

Example

Consider the expression ^a|b. I interpret this as (^a)|(b), expecting both a and b to be included in the language. However, the following NFAs (without trimming or renamed states) produce different results:

  1. Regex ^a|b: This results in an automaton with an empty language.

    @NFA-explicit
    %Alphabet-auto
    %Initial q3
    %Final q6
    q4 301 q6
    q5 97 q6
    
  2. Regex (^a)|b: This results in an automaton with the language {b}, although I would expect it to include a as well.

    @NFA-explicit
    %Alphabet-auto
    %Initial q3
    %Final q8 q7
    q3 98 q8
    q4 98 q8
    q6 301 q7
    
  3. Regex a|b: This produces an automaton with the expected language {a, b}.

    @NFA-explicit
    %Alphabet-auto
    %Initial q3
    %Final q4
    q3 97 q4
    q3 98 q4
    

Omitting ^ in regexes could partially suppress this issue.

@koniksedy koniksedy changed the title A combination of ^ with | in regex results in weird language Combining ^ with | in regex leads to unexpected behavior Oct 30, 2024
@Adda0 Adda0 self-assigned this Nov 18, 2024
@Adda0
Copy link
Collaborator

Adda0 commented Nov 18, 2024

This issue is now fixed through #459. The more complicated cases from other issues (#457, #437) will have to be tested after merging #461.

@Adda0 Adda0 closed this as completed Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants