0

How to rewrite the regex ^(?!master).+@ without the negative lookahead?

Natalie Perret
  • 6,629
  • 6
  • 52
  • 106

2 Answers2

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