{"id":2009,"date":"2025-02-11T11:21:12","date_gmt":"2025-02-11T04:21:12","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=2009"},"modified":"2025-02-11T20:38:51","modified_gmt":"2025-02-11T13:38:51","slug":"postgresql-regexp_match","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/","title":{"rendered":"PostgreSQL REGEXP_MATCH Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the PostgreSQL <code>REGEXP_MATCH<\/code> function to extract the first match of a regular expression from a string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-regexp_match-function-overview'>PostgreSQL REGEXP_MATCH Function Overview <a href=\"#postgresql-regexp_match-function-overview\" class=\"anchor\" id=\"postgresql-regexp_match-function-overview\" title=\"Anchor for PostgreSQL REGEXP_MATCH Function Overview\">#<\/a><\/h2>\n\n\n\n<p>In PostgreSQL, the <code>REGEXP_MATCH<\/code> function allows you to extract the first match of a <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-regular-expressions\/#introduction-to-posix-regular-expressions\" target=\"_blank\" rel=\"noreferrer noopener\">POSIX regular expression<\/a> from a string.<\/p>\n\n\n\n<p>The syntax of the <code>REGEXP_MATCH<\/code> function is as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">REGEXP_MATCH(string, pattern &#91;, flags])<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>string<\/code>: The input string to search.<\/li>\n\n\n\n<li><code>pattern<\/code>: The POSIX regular expression pattern to match.<\/li>\n\n\n\n<li><code>flags<\/code> (optional): Additional options to determine the behavior of the regular expression match, such as <code>'i'<\/code> for case-insensitive matching.<\/li>\n<\/ul>\n\n\n\n<p>The <code>REGEXP_MATCH<\/code> function returns an array of text (<code>TEXT[]<\/code>) containing the matched substring(s). It returns <code>NULL<\/code> if the <code>string<\/code> has no match.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-regexp_match-function-example'>PostgreSQL REGEXP_MATCH function example <a href=\"#postgresql-regexp_match-function-example\" class=\"anchor\" id=\"postgresql-regexp_match-function-example\" title=\"Anchor for PostgreSQL REGEXP_MATCH function example\">#<\/a><\/h2>\n\n\n\n<p>The following example uses the <code>REGEXP_MATCH<\/code> function to search for the first substring that has one or more digits:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  REGEXP_MATCH(<span class=\"hljs-string\">'iPhone 15 was introduced in 2023'<\/span>, <span class=\"hljs-string\">'\\d+'<\/span>) matches;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIFJFR0VYUF9NQVRDSCgnaVBob25lIDE1IHdhcyBpbnRyb2R1Y2VkIGluIDIwMjMnLCAnXGQrJykgbWF0Y2hlczs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>The <code>\\d+<\/code> regular expression matches one or more digits. Therefore, the function returns the first match, which is <code>15<\/code>, not <code>2023<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> matches\n<span class=\"hljs-comment\">---------<\/span>\n {<span class=\"hljs-number\">15<\/span>}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The result is an array that contains the matched substring.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='extracting-multiple-groups'>Extracting multiple groups <a href=\"#extracting-multiple-groups\" class=\"anchor\" id=\"extracting-multiple-groups\" title=\"Anchor for Extracting multiple groups\">#<\/a><\/h2>\n\n\n\n<p>You can use capturing groups <code>()<\/code> in the regex pattern to extract specific parts of the match:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  REGEXP_MATCH(\n    <span class=\"hljs-string\">'iPhone 15 was introduced on 09-12-2023'<\/span>,\n    <span class=\"hljs-string\">'(\\d{2})-(\\d{2})-(\\d{4})'<\/span>\n  ) matches;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIFJFR0VYUF9NQVRDSCggJ2lQaG9uZSAxNSB3YXMgaW50cm9kdWNlZCBvbiAwOS0xMi0yMDIzJywgJyhcZHsyfSktKFxkezJ9KS0oXGR7NH0pJyApIG1hdGNoZXM7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">   matches\n<span class=\"hljs-comment\">--------------<\/span>\n {<span class=\"hljs-number\">09<\/span>,<span class=\"hljs-number\">12<\/span>,<span class=\"hljs-number\">2023<\/span>}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the result array contains three digits corresponding to the three capturing groups in the regular expression.<\/p>\n\n\n\n<p>To access the nth element of the result array, you use the square bracket notation with the index (1-based index).<\/p>\n\n\n\n<p>For example, the following query returns the year from the result array:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  (REGEXP_MATCH(\n    <span class=\"hljs-string\">'iPhone 15 was introduced on 09-12-2023'<\/span>,\n    <span class=\"hljs-string\">'(\\d{2})-(\\d{2})-(\\d{4})'<\/span>\n  )) &#91;<span class=\"hljs-number\">3<\/span>] released_year;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUICggUkVHRVhQX01BVENIKCAnaVBob25lIDE1IHdhcyBpbnRyb2R1Y2VkIG9uIDA5LTEyLTIwMjMnLCAnKFxkezJ9KS0oXGR7Mn0pLShcZHs0fSknICkgKSBbM10gcmVsZWFzZWRfeWVhcjs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> released_year\n<span class=\"hljs-comment\">---------------<\/span>\n <span class=\"hljs-number\">2023<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='using-regexp_match-with-table-data'>Using REGEXP_MATCH with Table Data <a href=\"#using-regexp_match-with-table-data\" class=\"anchor\" id=\"using-regexp_match-with-table-data\" title=\"Anchor for Using REGEXP_MATCH with Table Data\">#<\/a><\/h2>\n\n\n\n<p>We&#8217;ll use the <code>products<\/code> table from the <code>inventory<\/code> database:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"159\" height=\"254\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png\" alt=\"PostgreSQL REGEXP_MATCH function - sample table\" class=\"wp-image-1051\"\/><\/figure>\n\n\n\n<p>The following query uses the <code>REGEXP_MATCH<\/code> function to extract the first number from product names in the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  product_name,\n  REGEXP_MATCH(product_name, <span class=\"hljs-string\">'\\d+'<\/span>) number\n<span class=\"hljs-keyword\">FROM<\/span>\n  products;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSwgUkVHRVhQX01BVENIKHByb2R1Y3RfbmFtZSwgJ1xkKycpIG51bWJlciBGUk9NIHByb2R1Y3RzOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">        product_name        | number\n<span class=\"hljs-comment\">----------------------------+--------<\/span>\n Samsung Galaxy S24         | {<span class=\"hljs-number\">24<\/span>}\n Apple iPhone <span class=\"hljs-number\">15<\/span>            | {<span class=\"hljs-number\">15<\/span>}\n Huawei Mate <span class=\"hljs-number\">60<\/span>             | {<span class=\"hljs-number\">60<\/span>}\n Xiaomi Mi <span class=\"hljs-number\">14<\/span>               | {<span class=\"hljs-number\">14<\/span>}\n Sony Xperia <span class=\"hljs-number\">1<\/span> VI           | {<span class=\"hljs-number\">1<\/span>}\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='regexp_match-vs-regexp_matches'>REGEXP_MATCH vs. REGEXP_MATCHES <a href=\"#regexp_match-vs-regexp_matches\" class=\"anchor\" id=\"regexp_match-vs-regexp_matches\" title=\"Anchor for REGEXP_MATCH vs. REGEXP_MATCHES\">#<\/a><\/h2>\n\n\n\n<p>The <code>REGEXP_MATCH<\/code> function returns the first match, while the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_matches\/\">REGEXP_MATCHES<\/a><\/code> function returns all matches as a set of an array. <\/p>\n\n\n\n<p>For example, this query uses the <code>REGEXP_MATCHES<\/code> function to return all substrings that contain one or more digits as a set of arrays of text:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  REGEXP_MATCHES(<span class=\"hljs-string\">'iPhone 15 was introduced in 2023'<\/span>, <span class=\"hljs-string\">'\\d+'<\/span>, <span class=\"hljs-string\">'g'<\/span>) matches;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIFJFR0VYUF9NQVRDSEVTKCdpUGhvbmUgMTUgd2FzIGludHJvZHVjZWQgaW4gMjAyMycsICdcZCsnLCAnZycpIG1hdGNoZXM7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> matches\n<span class=\"hljs-comment\">---------<\/span>\n {<span class=\"hljs-number\">15<\/span>}\n {<span class=\"hljs-number\">2023<\/span>}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='common-use-cases'>Common Use Cases <a href=\"#common-use-cases\" class=\"anchor\" id=\"common-use-cases\" title=\"Anchor for Common Use Cases\">#<\/a><\/h2>\n\n\n\n<p>The <code>REGEXP_MATCH<\/code> function can be helpful in the following cases:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data Extraction<\/strong>: Extracting data from text such as phone numbers, emails, and error codes.<\/li>\n\n\n\n<li><strong>Data Validation<\/strong>: Validate data based on a specific pattern.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='performance-considerations'>Performance Considerations <a href=\"#performance-considerations\" class=\"anchor\" id=\"performance-considerations\" title=\"Anchor for Performance Considerations\">#<\/a><\/h2>\n\n\n\n<p>Here are some performance considerations when using the <code>REGEXP_MATCH<\/code> function:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Regex Complexity<\/strong>: If you use complex regular expression patterns, the function will be slow, especially with a table with many rows.&nbsp;Ensure to optimize your regular expression patterns for performance.<\/li>\n\n\n\n<li><strong>Index Utilization<\/strong>: The queries with the <code>REGEXP_MATCH<\/code> function generally cannot utilize indexes, which results in full table scans. If the performance is critical, you can consider using functional indexes.<\/li>\n\n\n\n<li><strong>Flags<\/strong>: The flags like <code>'i'<\/code> may add overhead so ensure using it only when necessary.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code><code>REGEXP_MATCH<\/code><\/code> function to extract the first match of a substring based on a POSIX regular expression.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2009\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL REGEXP_MATCH Function\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2009\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL REGEXP_MATCH Function\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll learn how to sue the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1800,"menu_order":21,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2009","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL REGEXP_MATCH Function<\/title>\n<meta name=\"description\" content=\"You&#039;ll learn how to use the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL REGEXP_MATCH Function\" \/>\n<meta property=\"og:description\" content=\"You&#039;ll learn how to use the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-11T13:38:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png\" \/>\n\t<meta property=\"og:image:width\" content=\"159\" \/>\n\t<meta property=\"og:image:height\" content=\"254\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/\",\"name\":\"PostgreSQL REGEXP_MATCH Function\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"datePublished\":\"2025-02-11T04:21:12+00:00\",\"dateModified\":\"2025-02-11T13:38:51+00:00\",\"description\":\"You'll learn how to use the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2024\\\/12\\\/products.png\",\"width\":159,\"height\":254,\"caption\":\"PostgreSQL Expression Index\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/postgresql-regexp_match\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL String Functions\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-string-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL REGEXP_MATCH Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL REGEXP_MATCH Function","description":"You'll learn how to use the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL REGEXP_MATCH Function","og_description":"You'll learn how to use the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-02-11T13:38:51+00:00","og_image":[{"width":159,"height":254,"url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/","url":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/","name":"PostgreSQL REGEXP_MATCH Function","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","datePublished":"2025-02-11T04:21:12+00:00","dateModified":"2025-02-11T13:38:51+00:00","description":"You'll learn how to use the PostgreSQL REGEXP_MATCH function to extract the first match of a regular expression from a string.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2024\/12\/products.png","width":159,"height":254,"caption":"PostgreSQL Expression Index"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/postgresql-regexp_match\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL String Functions","item":"https:\/\/www.pgtutorial.com\/postgresql-string-functions\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL REGEXP_MATCH Function"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=2009"}],"version-history":[{"count":12,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2009\/revisions"}],"predecessor-version":[{"id":2042,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2009\/revisions\/2042"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1800"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=2009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}