Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

When i need to validate user input in fields it is often necessary to make sure only a limited set of characters is used.

Example could be European VAT Numbers, Phone, Container ID Code ...

The current REGEXP_SUBSTR Function is not able to match several accurencase of a given pattern in one go.


REGEXP_REPLACE( expression, regular-expression 
[, start-offset [ , occurrence-number [, escape-expression
[, regex-parameter ] ] ] ] )


  • regexp-paramter g Global search; i Case Insensitive; ....

Samples :

// In JScript they use a RegEx Parameter **g** to use the RegEx globaly against the
// searchstring 
regexp_replace( "0049-282 8/182", "[^0-9]", "") --> "00492828182"

// With grouped tagged expression to use in replacement string
regexp_replace( "0049 282 8182", "^00(\S*) (\S*) (.*)", "+$1 \($2) $3") --> "+49 (282) 8182"

Oracle also has a implementation of it

See this Question to see more reasons to implement REGEXP_REPLACE

asked 26 Jan '10, 12:09

Thomas%20Duemesnil's gravatar image

Thomas Dueme...
accept rate: 17%

I second this proposal for similar reasons.

(26 Jan '10, 13:36) Volker Barth

This is another one of those features that we have discussed within the engineering team on several occassions. I too have had many times that I've wanted to do be able to find a pattern within a string and replace it with a different one. But alas, regular expressions are complicated not only to understand and use but to implement and perform well. As such, this feature is already on the list of possible enhancements to be put into a future release.

permanent link

answered 26 Jan '10, 12:45

Mark%20Culp's gravatar image

Mark Culp
accept rate: 41%


I agree Mark! Regular expressions are complicated. It's my humble opinion that the purpose of any computer code, wether it be SQL, Java, PHP, Powerbuilder, or any other language, is for HUMANS to read and manage -- not computing systems... it's the systems' job to translate that code into something that they can deal with. While I fully appreciate the power of regex, I hate everything about it... precisely because it's incomprensible for many of us mortals.

(27 Apr '11, 21:01) Ron Hiner

Obligatory xkcd reference:

(27 Apr '11, 23:07) Graeme Perrow
Replies hidden

...and don't forget to look at the tool tip:)

(28 Apr '11, 03:27) Volker Barth

I should add that this similar topic was discussed as part of this question here, and was noted as part of the formatting enhancement opportunities in CR #728186.

(25 Jan '13, 09:58) Jeff Albion
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 26 Jan '10, 12:09

question was seen: 5,903 times

last updated: 16 Dec '15, 09:50