Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:11:54+00:00 2026-05-25T20:11:54+00:00

Using PostgreSQL v.8.2.14, I’m trying to build a regexp with several branches, some of

  • 0

Using PostgreSQL v.8.2.14, I’m trying to build a regexp with several branches, some of which are case-insensitive, the others not.

Consider the following perl one-liner:

% echo 'foo Foo bar Bar' | perl -pe 's/(foo|(?i:bar))/_\1/g'
_foo Foo _bar _Bar

I thought I would get there with:

select regexp_replace('foo Foo bar Bar','(foo|((?i)bar)',E'_\\1','g');

But I get: ERROR: invalid regular expression: quantifier operand invalid.
Note that the regex_flavor is advanced, and BTW when I put the (?i) at the very beginning of the regexp, then there is no error:

select regexp_replace('foo Foo bar Bar','(?i)(foo|bar)',E'_\\1','g');
 _foo _Foo _bar _Bar

Any help gladly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:11:54+00:00Added an answer on May 25, 2026 at 8:11 pm

    The (?i) (and related options) are only valid at the beginning of the expression. From the fine manual:

    An ARE may begin with embedded options: a sequence (?xyz) (where xyz is one or more alphabetic characters) […]

    Emphasis mine. The (?xyz) options are like the trailing /.../xyz options in the regexes of other languages. Also note that the 9.0 manual uses the same language so you can’t just upgrade your way around this.

    Looks like you need two regexp_replace calls:

    > select regexp_replace(regexp_replace('foo Foo bar Bar', 'foo', E'_\\&', 'g'), 'bar',  E'_\\&', 'ig');
       regexp_replace   
    --------------------
     _foo Foo _bar _Bar
    

    Or do the case-insensitive matching the hard way (i.e. character classes):

    > select regexp_replace('foo Foo bar Bar', '(foo|[Bb][Aa][Rr])', E'_\\1', 'g');
       regexp_replace   
    --------------------
     _foo Foo _bar _Bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing a database schema using PostgreSQL. I have some doubts about which design
I am using Postgresql and my player model has some associations such as: class
I am using postgreSQL. I have a column that: NOT NULL However when I
Using PostgreSQL 8.4, I'm trying to put together the following query: SELECT (field_a +
I am trying to create a database table using PostgreSQL but I am unable
We are using PostgreSQL with JPA which maps large strings to columns with type
I've recently started using PostgreSQL and I'm trying to do things the right way
PostgreSQL documentation recommends using a CallableStatement to call stored procedures. In the case of
I'm using PostgreSQL 8.1.4. I've 3 tables: one being the core (table1), others are
I'm using PostgreSQL 7.4.19. Why can I not use a basic SQL statement as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.