1

Trying to compare regular expressions from mine database to function parameters and got the following false result .. But if i go to https://regexr.com/ and try to compare with the same regular expression and the nickname i got match ..

Need your help , what i am doing wrong ?

select nickname_r from regex; // Here the regex that below

select '([0-9a-zA-Z.-_\=+\@]{2,15})' ~ 'Maks.+'; // RESULT false

set search_path = "postgres",coupon_system;
create or replace function loginValidator(nickname varchar, email varchar, u_password varchar) returns boolean as $$
    DECLARE
        checked boolean := false; n_regex varchar; e_regex varchar; p_regex varchar;
    BEGIN 

      select nickname_r , email_r, password_r into n_regex, e_regex, p_regex from regex;
      IF n_regex ~ nickname AND e_regex ~ email AND p_regex ~ u_password 
      THEN checked := true; 
      END IF;

     return checked;
    END;
$$ language plpgsql;

select loginValidator('Maks.+','[email protected]','+_Maks1988');

select nickname_r from regex;

select '([0-9a-zA-Z\.\-\_\=\+\@]{2,15})' ~ 'Maks.+'; // RESULT false

1 Answer 1

1

A pattern should be on the right side of the operator:

select 'Maks.+' ~ '([0-9a-zA-Z\.\-\_\=\+\@]{2,15})'; 
-- yields true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.