PHP兼容的正则表达式,以获取刻度之间的所有内容

I'm trying to grab BaseItemCode from the following phrase:

FOREIGN KEY (`BaseItemCode`) REFERENCES `BaseItems`

This is what I currently have, but I don't know how to exclude the characters '`', '(', and ')'

(?<=FOREIGN KEY)\s+\K(\(`[A-Za-z0-9]+`\))

It grabs (`BaseItemCode`)


As per Marty's comment, this gave me:

(?<=FOREIGN KEY)\s+\K\(`([A-Za-z0-9]+)`\)

Which retrieves 'BaseItemCode' in group 2.


Ah! I got one more step ahead, the following grabs exactly what I need:

(?<=FOREIGN KEY \(`)[A-Za-z0-9]+(?=`\))

Modify your regex to:

(?<=FOREIGN KEY)\s+\K(\(`([A-Za-z0-9]+)`\))

Group 2 will contain BaseItemCode

If you just want to match BaseItemCode, without using groups, use this regex:

(?<=FOREIGN KEY\s\(`)\w+(?=`\))