How to rewrite the regex ^(?!master).+@ without the negative lookahead?
Asked
Active
Viewed 393 times
0
Natalie Perret
- 6,629
- 6
- 52
- 106
-
What exactly are you trying to match? – AleksW Apr 15 '19 at 13:01
-
1Why do you not want the negative lookahead? – Sweeper Apr 15 '19 at 13:01
-
@Sweeper not longer supported in the engine I am forced to use... – Natalie Perret Apr 15 '19 at 13:03
-
@AleksW anything that does not start with `master` followed by anything with an `@` – Natalie Perret Apr 15 '19 at 13:04
-
1@ndnenkov sure, actually it's the kind of regex that can be accepted in the gitlab-ci.yml, it used to be the case that regex worked, but since the last update, everything is broken. – Natalie Perret Apr 15 '19 at 13:12
2 Answers
2
You may phrase this problem as being logically equivalent to saying match any string which does not begin with master, and which contains an at symbol:
input = "some random text @";
if (input !~ /^master/ && input =~ /.*@.*/) # or /.*@$/ if it must end in an @
puts "MATCH"
end
Tim Biegeleisen
- 451,927
- 24
- 239
- 318
2
^(?:[^m]|m[^a]|ma[^s]|mas[^t]|mast[^e]|maste[^r]).*@
ndnenkov
- 34,386
- 9
- 72
- 100
-
not supposed to have a `+` instead of `*` at the end: `^(?:[^m]|m[^a]|ma[^s]|mas[^t]|mast[^e]|maste[^r]).+@`? – Natalie Perret Apr 15 '19 at 13:24
-
2@EhouarnPerret the `+` means "one or more characters", while `*` means "zero or more characters". Given that we already matched at least one character in the brackets (for example `[^m]` is exactly one character), we may or may not need another one. Hence why it's `*` and not `+`. – ndnenkov Apr 15 '19 at 13:27
-
-