3

Case: To accept person_name satisfying following criteria:

  1. Allows any alphabetic symbols
  2. Space
  3. Dash
  4. Apostrophe
  5. Accent grave

Some pre-calculation has been performed to store the name in the string "PERSON_NAME"

LOGIC: SUBSTR(REGEXP_REPLACE(PERSON_NAME,'[^A-Za-z .`''-]+',''),0,50)

SELECT SUBSTR(REGEXP_REPLACE('cafè','[^A-Z|a-z| |.|`|''|-]+'),0,50) 
    FROM dual;

Passing almost all cases except in case of accented characters:

For example:

Expected result: cafè [i.e symbol above e ` should not be filtered out]

Actual Result: caf

1
  • what should be filtered out ? I mean what's the difference with the original string ? Commented Apr 11, 2019 at 13:54

1 Answer 1

1

You can use :

select SUBSTR(REGEXP_REPLACE('cafè-` t *'' {','[[:digit:]]') ,0,50) as "String"
  from dual;

String
--------------
cafè-` t *' {

since there's no information about numeric expressions in your restriction list.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, your column aliasing as "String" results in an error being thrown: SQL Error: ORA-00907: missing right parenthesis
Thank you, @BarbarosÖzhan. One last doubt: Is it a bad practice to put the accented vowels as a part of the REGEX itself? select substr(REGEXP_REPLACE('cafè','[^A-Z|a-z| |.||''|-|À|È|Ì|Ò|Ù|à|è|ì|ò|ù]+'),0,50) from dual; I want to allow to allow only the accent grave[] vowels. eg: allowed -vis-à-vis [result = visàvis] not allowed: Cissé [result = Ciss]
@Saiprasadshankar you're welcome. I think there's no need to list explicitly all the accented chars, if you use [[:digit:]], but I didn't understand from your last sample that you want to remove or not to remove non-alphabetic chars ...
Hello @BarbarosÖzhan, Another extension of this task is to allow a minimum of 2 charachters and a maximum of 50. In my substr() I have taken 0 and 50. So I I start from the beginning of the string and get only a maximum of 50 charachtcers. Is there a way to specify the minimum range as well? As using SUBSTR(2,50) skips the first few charachters as that specifies the starting point.
@Saiprasadshankar can you explain what you mean with an example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.