[英]Regular Expression to get a string between parentheses and inside the string literal in Javascript
let s = "Cannot add or update a child row: a foreign key constraint fails (`testdb`.`products`, CONSTRAINT `products_ibfk_3` FOREIGN KEY (`category_id`) REFERENCES `product_categories` (`id`))"
here I need to extract the FOREIGN key inside the literal with parenthesis ex.在这里,我需要用括号 ex 提取文字中的 FOREIGN 键。 extracted = "category_id"
. extracted = "category_id"
。 I don't know how to do with regexp
.我不知道如何处理regexp
。
Anyone, can you help me?任何人,你能帮帮我吗?
Thank in advance for your great community support.提前感谢您对社区的大力支持。
let s = "Cannot add or update a child row: a foreign key constraint fails (`testdb`.`products`, CONSTRAINT `products_ibfk_3` FOREIGN KEY (`category_id`) REFERENCES `product_categories` (`id`))"; let match = /FOREIGN KEY \(`([\w]*)`\)/.exec(s); let extracted = match[1]; console.log(extracted);
Edit:编辑:
The pattern( /FOREIGN KEY (([\w]*))/
) does extract "FOREIGN KEY (category_id)" and "category_id" from string.模式( /FOREIGN KEY (([\w]*))/
)确实从字符串中提取“FOREIGN KEY (category_id)”和“category_id”。 Please refer to this url .请参阅此 url 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.