need to create regular expression for below pattern

i need to create regex pattern for below

[#706+#701]
[[#708-#717]/2]
[#712/2]

what would be the regex expression

is this surrounded by text you dont want to select ?
whats an example that shows that...? (or else we couldnt prove that what we suggest would work.
On the otherhand, if the text you start with is only like you have shown us, then regex would not seem to have a purpose as you already have all the text you need. ..

#710=[#706+#701](First groove bottom)
#711=[#706+#707](Second Groove Bottom) 
#717=[#702+#716](Compensated tool diameter)
#712=[[#708-#717]/2](Diameter of tool path)
#713=[#712/2](Radius of tool path) 
#714=[#704*1.5]
#715=[#703*2]

above is my data and i need to extract only bleow data

[#706+#701]
[#706+#707] 
#702+#716]
[[#708-#717]/2]
[#712/2]
#704*1.5]
[#703*2]
(mytext <- c("#710=[#706+#701](First groove bottom)",
           "#711=[#706+#707](Second Groove Bottom)", 
           "#717=[#702+#716](Compensated tool diameter)",
           "#712=[[#708-#717]/2](Diameter of tool path)", 
           "#713=[#712/2](Radius of tool path)", 
           "#714=[#704*1.5]", 
           "#715=[#703*2]"))


(mytext2 <- regmatches(mytext,
           regexpr(pattern ="\\[(.*?)\\]",
        text = mytext) ))

thanks
i need to replace all '[' with '(' and ']' with ')'

you can either combine a few calls to stringr::str_replace, or first use stringr::str_sub to eliminate the first and last characters, and then paste0, to add new first and last characters

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.