program regexgen;
var
   neg : boolean;
   c   : char;
   s   : string;
   i   : integer;
   esc : set of char;
begin
   esc := ['^', '$', '[', '*', '.', '\', ']', '|', '?', '+'];
   neg := false;
   if (paramcount > 0) then 
      if upcase(paramStr(1)) = '-N' then
	 neg := true;

   {now the real stuff}
   s := '';
   {if neg and not EOLN then
      write('(');}
   while not EOLN do begin
      read(c);
      if not neg then begin
	 if (c in esc) then
	    write('\');
	 write(c);
      end
      else begin
	 if (length(s) > 0) then begin
	    write('|');
	    for i := 1 to length(s) do begin
	       if (s[i] in esc) then
		  write('\');
	       write(s[i]);
	   end;
	 end;

	 if (c in esc) then
	    write('([^\' + c + ']|$)')
	 else
	    write('([^' + c + ']|$)');
	 s := s + c;
      end;
   end;
   {if neg and (length(s) > 0) then
      write (')*');}

end.