Needing help for a RegEx (using Oracle REGEXP_LIKE) to identify strings that:
- Start with any of the following:
- P
- C
- (P)
- (C)
- ©
- are then followed by a space
- are then followed by any 4-digit numbers, where the first 2 digits in the number are 19 or 20.
- are then followed by a space
- are then followed by any other text
Sample matches:
(P) 2004 XYZ Company P 2018 This is some random text (C) 1994 More Random Text
Sample non-matches:
(P) XYZ Company P1976,Just Wow (C) 1856 Too Late For Gold
I've started with
^[PC©]\s
but, as a beginner, am stumped with how to handle the (P) and (C) cases, much less the complexities that follow with the year values.
CodePudding user response:
You may use the following pattern:
SELECT *
FROM yourTable
WHERE REGEXP_LIKE(text, '^([CP©]|\([CP]\)) (19|20)[0-9]{2} .*');
CodePudding user response:
A dirty solution is to just use alternation. For example, (abc|def)
will match abc
or def
.
For your case: ^(\(P\)|\(C\)|P|C|©) (19|20)\d{2} .*