REM Count how many letter there are
select regexp_count('ABC123', '[A-Z]'), /* This matches "A", "B" & "C" so returns 3 */
regexp_count('A1B2C3', '[A-Z]') /* This matches "A", "B" & "C" so returns 3 */
from dual
REGEXP_COUNT('ABC123','[A-Z]') | REGEXP_COUNT('A1B2C3','[A-Z]')/*THISMATCHES"A","B"&"C"SORETURNS3*/ | 3 | 3 |
---|
REM Count how many times one letter is followed by one number
select regexp_count('ABC123', '[A-Z][0-9]'), /* This matches "C1" so returns 1 */
regexp_count('A1B2C3', '[A-Z][0-9]') /* This matches "A1", "B2" & "C3" so returns 3 */
from dual
REGEXP_COUNT('ABC123','[A-Z][0-9]') | REGEXP_COUNT('A1B2C3','[A-Z][0-9]')/*THISMATCHES"A1","B2"&"C3"SORETURNS3*/ | 1 | 3 |
---|
REM Count how many times one letter is followed by one number at the start of a string
select regexp_count('ABC123', '^[A-Z][0-9]') /* This has no match so returns 0 */,
regexp_count('A1B2C3', '^[A-Z][0-9]') /* This matches "A1" so returns 1 */
from dual
REGEXP_COUNT('ABC123','^[A-Z][0-9]')/*THISHASNOMATCHSORETURNS0*/ | REGEXP_COUNT('A1B2C3','^[A-Z][0-9]')/*THISMATCHES"A1"SORETURNS1*/ | 0 | 1 |
---|
REM Count how many times a letter is followed by exactly two numbers
select regexp_count('ABC123', '[A-Z][0-9]{2}'), /* This matches "C12" so returns 1 */
regexp_count('A1B2C3', '[A-Z][0-9]{2}') /* This has no match so returns 0 */
from dual
REGEXP_COUNT('ABC123','[A-Z][0-9]{2}') | REGEXP_COUNT('A1B2C3','[A-Z][0-9]{2}')/*THISHASNOMATCHSORETURNS0*/ | 1 | 0 |
---|
REM Count how many times there are two occurrences of one letter followed by one number
select regexp_count('ABC123', '([A-Z][0-9]){2}'), /* This has no match so returns 0 */
regexp_count('A1B2C3', '([A-Z][0-9]){2}') /* This matches "A1B2" so returns 1 */
from dual
REGEXP_COUNT('ABC123','([A-Z][0-9]){2}') | REGEXP_COUNT('A1B2C3','([A-Z][0-9]){2}')/*THISMATCHES"A1B2"SORETURNS1*/ | 0 | 1 |
---|