0

Rule: 1. Start with R ; 2. One or more number ; 3. One space ; 4. Follow with other characters ;

Test case: Input : 'R1 ABC' 'R4 DEF' 'Randwick Acca' 'R11 PPP'

Expect Output : 'R1 ABC' 'R4 DEF' 'R11 PPP'

Regular expression : "R\d{1,} " I use regular expression tester, it works. https://regex-golang.appspot.com/assets/html/index.html?_sm_au_=iHVPMjQb0QjFkMTHfLJ4vK7214sJW

Test query:

WITH tbl AS (select t.column1 mycol from values('R1 ABC'),('R4 DEF'),('Randwick Acca'),('R11 PPP') t) SELECT * FROM tbl WHERE mycol regexp 'R\d{1,} ' ; 

Return NULL .

Thanks, Bin

1 Answer 1

1

1) where's the "any other character"? Because what you have ends with space, period

2) welcome to SQL. \ is a special character and needs to be escaped

So:

WHERE mycol regexp 'R\\d{1,} .*'; 

I tested it on your query and it seemed to work

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

1 Comment

there's also a shorthand for {1,} which is +, So R\\d+ .* also works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.