Ram
Ram

Reputation: 557

Regex in PostgreSQL doesn't work as expected

  1. ABCD9876S__9999.A001
  2. ABCD9876S__9999.A002

    • Always starts with ABCD
    • Followed by a mix of digits and alphabets
    • Followed by two underscores __
    • Followed by 9999.A00 1 or 2

I want to catch the above two strings using reg ex

I have :

ABCD.*9999\.A00[12]

This doesn't work in Postgres. How do I convert this? Is there an online tool?

Upvotes: 0

Views: 291

Answers (1)

The fourth bird
The fourth bird

Reputation: 163632

You could specify the character ranges that you want to allow using a character class and add the double undescore you want to be part of the match.

ABCD[a-zA-Z0-9]+__9999\.A00[12]

If the match should be from the start of the string use anchors ^ and $

See a postgre sql demo 1 | demo 2 using regexp_matches

Upvotes: 2

Related Questions