0

Here is my query which does work:

select composition from `drugs` where composition regexp "^Diclofenac([^)])"

And the output:

Diclofenac(50mg),Thiocolchicoside(8mg)                                              
Diclofenac(50mg),Thiocolchicoside(4mg)                                              
Diclofenac(75mg),Thiocolchicoside(4mg)                                              
Diclofenac(50mg),Thiocolchicoside(4mg)                                              
Diclofenac(50mg),Tamsulosin(0.4mg)                                                  
Diclofenac(50mg),Eperisone(50mg)                                                    
Diclofenac(50mg),Thiocolchicoside(8mg)                                              
Diclofenac(100mg),Rabeprazole(20mg)                                                 
Diclofenac(75mg)                                                                    
Diclofenac(50mg),Thiocolchicoside(8mg)                                              
Diclofenac(50mg),Serratiopeptidase(10mg)                                            
Diclofenac(100mg),Eperisone(150mg)                                                  
Diclofenac(4mg),Thiocolchicoside(50mg)                                              
Diclofenac(100mg),Eperisone(150mg)                                                  
Diclofenac(50mg),Thiocolchicoside(4mg)                                              
Diclofenac(50mg),Thiocolchicoside(8mg)                                              
Diclofenac(50mg),Nimesulide(100mg)                                                  
Diclofenac(50mg),Paracetamol(325mg),Thiocolchicoside(8mg)                           
Diclofenac(NA),Serratiopeptidase(NA)                                                
Diclofenac(50mg),Nimesulide(100mg)                                                  
Diclofenac(50mg),Thiocolchicoside(4mg)                                              
Diclofenac(50mg),Paracetamol(325mg),Thiocolchicoside(4mg)                           
Diclofenac(100mg),Rabeprazole(20mg)                                                 
Diclofenac(50mg),Serratiopeptidase(10mg)                                            
Diclofenac(50mg),Nimesulide(100mg)

I want to search for drugs where composition begins with Diclofenac() followed by "," followed by Thiocolchicoside(). Tried following but gives zero results.

select composition from `drugs` where composition regexp "^Diclofenac([^)]),Thiocolchicoside([^)])"

Edit: Created DB fiddle: https://www.db-fiddle.com/f/fkQkn2WKdax2KbZqt7rPQ/0

3
  • Those parentheses probably need to be escaped with backslashes: select composition from drugs where composition regexp "^Diclofenac\([^)]\),Thiocolchicoside\([^)]\)" Commented Sep 9, 2017 at 5:05
  • Didn't work :-( Commented Sep 9, 2017 at 5:09
  • [^)] merely says match any character, which is not ')'. Since you want to match multiple characters, you should say '[^)]+' . "+" means match 1 or more characters. Commented Sep 9, 2017 at 14:31

2 Answers 2

1
select composition from `drugs` where composition regexp "^Diclofenac\\([^)]+\\),Thiocolchicoside\\([^)]+\\)$"

Apart from adding '+' to match multiple non-right brace characters, i.e. [^)], you need to escape '(', because it has a special meaning in regular expressions

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

Comments

0

Try this pattern ^Diclofenac(.*,Thiocolchicoside\(.*\))

.*, means that anything before ,

\(.*\) means (anything in brackets)

1 Comment

I am assuming you meant ^Diclofenac(.*),Thiocolchicoside(.*). ".*" is greedy . It also selects following, for example: Diclofenac(50mg),Paracetamol(325mg),Thiocolchicoside(8mg)

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.