Preamble
The Oracle/PLSQL REGEXP_REPLACE function is an extension of the function REPLACE. This function, introduced in Oracle 10g, allows you to replace a sequence of characters in a string with a different set of characters using regular expression pattern mapping.
Syntax of the Oracle/PLSQL function REGEXP_REPLACE
REGEXP_REPLACE( string_id, pattern_id [, replacement_string_id [, start_position_id [, nth_appearance_id [, match_parameter_id ] ] ] ] ]
Parameters and function arguments
- string_id – A search line. It can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB or NCLOB.
- pattern_id – Template. Regular expression for comparison. It can be a combination of the following values:
| Meaning | Description |
| ^ | Corresponds to the beginning of the line. When using match_parameter with m, corresponds to the beginning of the string anywhere within the expression. |
| $ | Corresponds to the end of the line. When using match_parameter with m, it corresponds to the end of the string anywhere within the expression. |
| * | Corresponds to zero or more occurrences. |
| ? | Corresponds to one or more occurrences. |
| ? | Corresponds to zero or one entry. |
| . | Corresponds to any character except NULL. |
| | | Used as “OR” to specify more than one alternative. |
| [ ] | It is used to specify a list of matches where you try to match any of the characters in the list. |
| [^ ] | It is used to specify a nonmatching list where you try to match any character except for those on the list. |
| ( ) | Used for group expressions as subexpressions. |
| {m} | Corresponds m times. |
| {m,} | Matching at least m times. |
| {m,n} | Matching at least m times, but not more than n times. |
| \n | n is a number between 1 and 9. It corresponds to the n-th subexpression located in ( ) before \n. |
| [..] | Corresponds to a single element mappings that can be more than one character. |
| [::] | Meets the symbol class. |
| [==] | Corresponds to the class of equivalence. |
| \d | Corresponds to the digital symbol. |
| \D | Corresponds to a non-digital symbol. |
| \w | Corresponds to the text symbol. |
| \W | Corresponds to a non-text symbol. |
| \s | Corresponds to the space character. |
| \S | Doesn’t match the space character. |
| \A | Corresponds to the beginning of a line or corresponds to the end of a line before a new line character. |
| \Z | Corresponds to the end of the line. |
| *? | Corresponds to the previous pattern of zero or more occurrences. |
| +? | One or more entries correspond to the previous template. |
| ?? | Corresponds to the previous zero or one entry pattern. |
| {n}? | Corresponds to the previous template n times. |
| {n,}? | Corresponds to the previous template at least n times. |
| {n,m}? | Corresponds to the previous template at least n times, but not more than m times. |
- replacement_string_id – It’s optional. The corresponding templates in the string will be replaced with replace_string. If the replacement_string parameter is omitted, the function simply deletes all matching templates and returns the resulting string.
- start_position_id – Optional. This is the position in the string from which the search will start. If this parameter is omitted, by default it is 1, which is the first position in the string.
- nth_appearance_id – Optional. This is the n-th view of the pattern in the string. If this option is omitted, it defaults to 1, which is the first entry of the template in the string. If you specify 0 for this parameter, all template entries in the string will be replaced.
- match_parameter_id – It’s optional. This allows you to change the compliance behavior for the REGEXP_REPLACE condition. This can be a combination of the following values:
| Meaning | Description |
| ‘c’ | Performs register-sensitive alignment. |
| ‘i’ | Performs case insensitive alignment. |
| ‘n’ | Allows a character period (.) to match the character of a new string. By default, the metasymic period. |
| ‘m’ | The expression assumes that there are several lines where ^ is the beginning of a line and $ is the end of a line, regardless of the position of these characters in the expression. By default, the expression is assumed to be on the same line. |
| ‘x’ | The symbols of spaces are ignored. By default, the space characters are the same as any other character. |
The function REGEXP_REPLACE returns a string value.
If there are conflicting values for match_parameter, function REGEXP_REPLACE will use the last value.
The REGEXP_REPLACE function can be used in the following Oracle/PLSQL versions
Oracle 12c, Oracle 11g, Oracle 10g
Example of a match to the first word
Consider an example of using the REGEXP_REPLACE function to replace the first word in a string.
For example:
SELECT REGEXP_REPLACE ('Bing is a great search engine.', '^(\S*)', 'Google')
FROM dual;
--Result: 'Google is a great search engine.'
This example will return ‘Google is a great search engine.’ Because the beginning of the match at the beginning of the line, as indicated by ^, and then finds the first word according to (\S*). Then the function will replace this first word with ‘Google’.
Example of a number match
Let’s consider an example of how we will use the OracleREGEXP_REPLACE function to compare a pattern of digital characters.
For example:
SELECT REGEXP_REPLACE ('1, 4, and 10 numbers for example.', '\d', '@')
FROM dual;
--Result: @, @, and @@@ numbers for example.
This example will replace all numbers in the string, as specified in the \d template, with @.
We could change our template to search only for two-digit numbers
For example:
SELECT REGEXP_REPLACE ('1, 4, and 10 numbers for example', '(\d)(\d)', '@')
FROM dual;
--Result: 1, 4, and @ numbers for example
This example will replace a number that has two digits, as specified in the template (\d) (\d). In this case it will skip the numeric values 2 and 5 and replace 10 with @.
Now let’s see how we will use the REGEXP_REPLACE function with the table column to replace the two-digit numbers.
For example:
SELECT REGEXP_REPLACE (address, '(\d)(\d)', 'Str')
FROM contacts;
In this example, we will replace all two-digit values of the address field in the contacts table with ‘Str’.
This is an example of comparing several alternatives.
The next example we will look at involves using the | template. | the template is used as an ‘OR’ to specify multiple alternatives.
For instance:
SELECT REGEXP_REPLACE ('AeroSmith', 'a|e|i|o|u', 'R')
FROM dual;
-Result: ARrRSmRth
This example will return ‘ARrRSmRth’ because it looks for the first vowel (a, e, i, o or u) in the string. Since we didn’t specify a match_parameter value, the REGEXP_REPLACE function will perform a case sensitive search, which means that ‘A’ in ‘AeroSmith’ will not match.
We could modify our query to perform a case-insensitive search as follows:
SELECT REGEXP_REPLACE ('AeroSmith', 'a|e|i|o|u', 'R', 1, 0, 'i')
FROM dual;
--Result: RRrRSmRth
Now, since we specified match_parameter = ‘i’, the query will replace ‘A’ in the string. This time, ‘A’ in ‘AeroSmith’ will be matched with a template. Note also that we have specified the 5th parameter as 0 to replace all occurrences.
Now consider how you will use this function with the column.
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
How to Achieve Real Estate Cost Transparency with Enteros: AI SQL Analytics and AIOps Platform Intelligence
- 17 February 2026
- Database Performance Management
Introduction Real estate has evolved into a technology-driven industry. From digital property marketplaces and smart building platforms to tenant apps, CRM systems, leasing automation tools, and investment analytics dashboards—modern real estate enterprises depend on complex data ecosystems. Every lease agreement, rent payment, occupancy report, maintenance request, and investor presentation is powered by databases running behind … Continue reading “How to Achieve Real Estate Cost Transparency with Enteros: AI SQL Analytics and AIOps Platform Intelligence”
How to Optimize SaaS Performance and RevOps Efficiency with Enteros: Database Management and Cloud FinOps Intelligence
Introduction The SaaS business model promises scalable growth, recurring revenue, and predictable expansion. But behind every subscription dashboard, billing workflow, in-app analytics panel, and customer success metric lies a powerful—and often overlooked—engine: The database layer. In today’s technology sector, SaaS companies compete on speed, reliability, personalization, and cost efficiency. Every millisecond of latency impacts user … Continue reading “How to Optimize SaaS Performance and RevOps Efficiency with Enteros: Database Management and Cloud FinOps Intelligence”
What Telecom CIOs Should Know About AI SQL, Cost Attribution, and Predictive Cloud FinOps with Enteros
- 16 February 2026
- Database Performance Management
Introduction The telecommunications industry operates at a scale few sectors can match. Billions of call detail records (CDRs).Real-time 5G traffic management.Subscriber billing systems.Network performance analytics.IoT connectivity platforms.Streaming, messaging, roaming, and edge computing services. Behind every one of these services lies a complex, high-volume database ecosystem. And as telecom providers modernize into cloud-native, multi-cloud, and hybrid … Continue reading “What Telecom CIOs Should Know About AI SQL, Cost Attribution, and Predictive Cloud FinOps with Enteros”
How Enteros Combines Generative AI and Database Intelligence to Drive Predictable Revenue Operations Growth
Introduction Revenue Operations (RevOps) has evolved from a coordination function into a strategic growth engine. Modern enterprises rely on tightly integrated sales, marketing, finance, customer success, and product systems to generate predictable revenue. But behind every CRM update, pricing calculation, renewal forecast, pipeline report, and customer usage metric lies a critical foundation: The database layer. … Continue reading “How Enteros Combines Generative AI and Database Intelligence to Drive Predictable Revenue Operations Growth”