Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1soutv-00Em9j-BC for pgsql-admin@arkaria.postgresql.org; Fri, 13 Sep 2024 01:15:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1soutu-005rKv-GR for pgsql-admin@arkaria.postgresql.org; Fri, 13 Sep 2024 01:15:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1soutu-005rKk-4b for pgsql-admin@lists.postgresql.org; Fri, 13 Sep 2024 01:15:06 +0000 Received: from mail-vs1-xe35.google.com ([2607:f8b0:4864:20::e35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1soutq-000u0j-Mn for pgsql-admin@lists.postgresql.org; Fri, 13 Sep 2024 01:15:05 +0000 Received: by mail-vs1-xe35.google.com with SMTP id ada2fe7eead31-49bddfd1edeso127244137.0 for ; Thu, 12 Sep 2024 18:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726190102; x=1726794902; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YNru9opR4x6qlsyG/DXIJmtrZTWLbYEfsq7OPLwqnfE=; b=RBDL6n/lzmgapczjWWzhNbtmxY0pbJQF6UFed5ujWxYu20yZ+JmwDesKcTonX5hTRd jKTzgLOdbp8ptl55UkIVdVMVN+3v6VN01JykXbkdhXPdholo7TRwRBFXgjIs8wzGxCFc dc7m4Mlt2X8FawgH8j1iRpyN4pCaiZ5N69LK3ENvRkFl4PE8GTut8jslp1wf9vXI5r3e EB3MZfXVokLIk1EFWmMbxvKRu/QXUkSi98Ua7ww2Z0aI4T0MAaIvnlXQdv23AHMZOp2Q 1H7RfMwMZg5aKKp9FmPthOUDUcFWwuK4VVVmKJXGosOgdKFc3h8UPpcfnGZdXIFJK3HN CSEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726190102; x=1726794902; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YNru9opR4x6qlsyG/DXIJmtrZTWLbYEfsq7OPLwqnfE=; b=cFmjsJEAX9VpYRsBjjsONv5ZZAhulYiW0N4zp/e6hsD/qfgBfzz+3gAbi7ZsaXYraB R9DuR6MHFpLy4MCIIBGUwfW/WF5ZQTowV60jWPzzBpuX53E4kzRdAq24nn2bh0yovn4c JTboiFWNLmgMWJp3JOjPFhaPK2OrorzQF9PbVCkz8WYgs21PoboVB0HSMv1cHN7qSCnY KBk7E2JpO4j7tnot7lS6nPHMC/J4KPHfaCyWHSw5nNIcmcW6PPHMf7wXIqUVdIgbYaX6 jCoytzhEYKMDzuc7c9S+NlJSKs/2v2x4Yov/6iS4N1DrvVXBrQHMHZICKyUCTpMaV78H yaRQ== X-Gm-Message-State: AOJu0YxY4UmfPLZbM6ASdkvuByuMHBtIR0CXn3oClnP7N0O0C/2/lWC8 eojJvVkT3jSi3WA7KdlwmwCzWMzTOdp18wnorrLOZ3XdlT/ca9PqfsARRgRDv9VgPYZp9VuBIhw TNwVEO43596z4xQBfYchBTBHVRF2cFpxX3A9r6w== X-Google-Smtp-Source: AGHT+IGhr438PZ1Z2Pezb3KYlX7DepEEsDxhyH2mTbYh1wi91ycz2ROOPOULkLwWZ794+n+jOrGmVTyA4h5FLRPKOOs= X-Received: by 2002:a05:6102:4415:b0:49b:f8a2:2f87 with SMTP id ada2fe7eead31-49d4f6b6012mr1354972137.22.1726190102031; Thu, 12 Sep 2024 18:15:02 -0700 (PDT) MIME-Version: 1.0 References: <18A99BB3-EB26-47A3-94D6-D951E984D982@aweber.com> In-Reply-To: <18A99BB3-EB26-47A3-94D6-D951E984D982@aweber.com> From: jian he Date: Fri, 13 Sep 2024 09:14:51 +0800 Message-ID: Subject: Re: Regexp_replace help To: Chris Hoover Cc: pgsql-admin@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 13, 2024 at 5:18=E2=80=AFAM Chris Hoover wr= ote: > > Looking for some help here. I have a string that has =E2=80=98code1234= =E2=80=99 in it. The 1234 can vary and I won=E2=80=99t know what they woul= d be. Trying to figure out how to use regexp_replace to trim down the stri= ng, but unsure how to keep the =E2=80=98code1234=E2=80=99 in the string. > > > The search should be =E2=80=98 code[0-9]+? .*=E2=80=99. However, I don=E2= =80=99t understand what the replace should be. > > I.E.: > SELECT regexp_replace(=E2=80=99This is my test string that caused code12 = from abc=E2=80=99, > =E2=80=98 code[0-9]+? .*=E2=80= =99, > =E2=80=98What should this be so = I keep the code12?=E2=80=98) > Desire result: > =E2=80=99This is my test string that caused code12=E2=80=99 > > > SELECT regexp_replace(=E2=80=99This is my second test string and it is ca= using code1234 from def. The weather is nice. :)=E2=80=99, > =E2=80=98 code[0-9]+? .*=E2=80= =99, > =E2=80=98What should this be so = I keep the code1234?=E2=80=99) > Desire result: > =E2=80=98This is my second test string and it is causing code1234=E2=80= =99 > please try these. select SUBSTRING($$This is my test string that caused code12 from abc$$ from '.*(?:code[0-9]\S+)'); select SUBSTRING($$This is my test string that caused code12s1 from abc$$ from '.*(?:code\S+)'); SELECT SUBSTRING($$This is my second test string and it is causing code1234 from def. The weather is nice. :$$ from '.*(?:code\S+)');