-2

i do this

select distinct city 
from station 
where regexp_like(city,'^[^aeiou].*[^aeiou]$','i') and regexp_like(city,'^[^aeiou]\w+[^aeiou]$','i');

. it is wrong i know. but can someone explain to me where i am wrong at based on the question ? any answer will appreciated. thank you.

here link screenshot from the question.

hackerrank problem

nbk
  • 45,398
  • 8
  • 30
  • 47
  • Do not start **or** do not end. You have no alternatives in the code: be it a plain `or` or regex alternative `|` – astentx Jan 17 '23 at 16:44
  • @astentx oo i see sir, so if i prefer to use "where regexp_like(city,'^[^aeiou].*$,'i'') or regexp_like(city,'^.*[^aeiou]$','i')" is it will cause any problem ? i kinda new to this regexp thing. anyway, thank you for the explanation. – Teguh Pambudi Jan 18 '23 at 14:17

1 Answers1

1

Does it have to be regex? substr handles it in a simple manner:

SQL> with station (city) as
  2    (select 'Zagreb' from dual union all
  3     select 'Athens' from dual union all
  4     select 'Rome'   from dual union all
  5     select 'Ottawa' from dual
  6    )
  7  select distinct city
  8      from station
  9      where upper(substr(city, 1, 1)) not in ('A', 'E', 'I', 'O', 'U')
 10        and upper(substr(city, -1))   not in ('A', 'E', 'I', 'O', 'U');

CITY
------
Zagreb

SQL>

If you must use regex, then

  7  select distinct city
  8      from station
  9      where regexp_like(city, '^[^aeiou].*[^aeiou]$', 'i');

CITY
------
Zagreb

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57