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

Syntax for RegexString flags? #5

Open
singularitti opened this issue Nov 26, 2020 · 6 comments
Open

Syntax for RegexString flags? #5

singularitti opened this issue Nov 26, 2020 · 6 comments

Comments

@singularitti
Copy link
Contributor

How to write multiline / case-insensitive / single line, etc., RegexString? Just like what's provided in Regex?

julia> r"a+.*b+.*?d$"ism
r"a+.*b+.*?d$"ims

julia> match(r"a+.*b+.*?d$"ism, "Goodbye,\nOh, angry,\nBad world\n")
RegexMatch("angry,\nBad world")
@jkrumbiegel
Copy link
Owner

I didn't implement flags, because they are not spliced into the regex string like the other things are. But I think you could just pass the flags at the moment where you convert the RegexString into the actual Regex. Aren't the flags keyword arguments to the Regex constructor?

Maybe I should think about how to add a more convenient method for flags

@singularitti
Copy link
Contributor Author

singularitti commented Nov 26, 2020

The thing is,

  1. there is no Regex(r::RegexString, flags). If I have a RegexString, I need to use Regex(rs.s, "m") to convert.
  2. How do I do the multiline part when constructing RegexString using *? I have to add * "\s*" in between. I have something like:
capture(
    either(
        rs"A",
        "b",
        "c",
    );
    as = "X",
) *
rs"\h*d =\h*" *
NUMBER *
rs",  a" *
NUMBER

where either & rs"\h*d =\h*" should be connected by a line break, now I have to add a \s* manually.

@jkrumbiegel
Copy link
Owner

Yeah I could add a regex constructor with flags.

I don't understand the other question, what are you trying to do? \s is any whitespace, not specifically a newline

@singularitti
Copy link
Contributor Author

I don't understand the other question, what are you trying to do? \s is any whitespace, not specifically a newline

That's why I am using this package 😂. I am not very familiar with regexes, so I need to build regexes with code.

@jkrumbiegel
Copy link
Owner

Maybe you can describe what you're trying to match, and I can help you what the best syntax would be?

@singularitti
Copy link
Contributor Author

Maybe you can describe what you're trying to match, and I can help you what the best syntax would be?

Just consider any multiline matching, or ignoring the case matching.

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