简体   繁体   中英

How do I remove everything outside of parenthesis in a string using regex

How do I remove everything outside of parenthesis in a string using regex. I'm just trying to get what's in the parenthesis.

I'm looping through a bunch of records. To keep things simple for this example, I'm using just 1 record (each record can have multiple values).

So if this my record string:

<cfset servicelist = "Orthopedic, Joint (AFDA); Orthopedic Surgery (ACDA)">

What regex do I add to this variable:

<cfset Codes = "">

I'm trying to grab the following codes out of the record:

(AFDA)(ACDA)

This should do it (\\(\\w+\\))

https://regex101.com/r/ns3HYN/2

\\( matches the character ( literally (case sensitive)
\\w+ matches any word character (equal to [a-zA-Z0-9_] )
+ Quantifier — Matches between one and unlimited times, as many times as possible
\\) matches the character ) literally (case sensitive)

在此处输入图片说明


Also Try @WiktorStribiżew Example .*?(\\(\\w+\\))? ** and replace with $1 * (or \\1 in ColdFusion)

在此处输入图片说明

.*? matches any character (except for line terminators)
? Quantifier — Matches between zero and one times, as many times as possible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM