How to delete the text of parentheses in a sentence Topic is solved
How to delete the text of parentheses in a sentence
Like "Absorb and integrate (people, ideas, or culture) into a wider society or culture." to become "Absorb and integrate into a wider society or culture."
Re: How to delete the text of parentheses in a sentence
RegEx (prefered) or StrSplit()
Re: How to delete the text of parentheses in a sentence Topic is solved
Code: Select all
str := "Absorb and integrate (people, ideas, or culture) into a wider society or culture."
newStr := RegExReplace(str, "( \(|\()[^\)]*?\)")
MsgBox, % str "`n`n" newStr
Re: How to delete the text of parentheses in a sentence
@boiler is back in town
Re: How to delete the text of parentheses in a sentence
As BoBo suggested,
Code: Select all
str := "Absorb and integrate (people, ideas, or culture) into a wider society or culture."
newStr := StrSplit(str, [" (", ")"])
MsgBox, % str "`n`n" newStr[1] newStr[3]
Re: How to delete the text of parentheses in a sentence
dirty:
Code: Select all
A := new biga() ; requires https://www.npmjs.com/package/biga.ahk
string := "Absorb and integrate (people, ideas, or culture) into a wider society or culture."
msgbox, % A.replace(string, "/\(.+\) /", "")
; => "Absorb and integrate into a wider society or culture."
Re: How to delete the text of parentheses in a sentence
Code: Select all
str := "The solution should probably handle cases (like this one) with multiple pairs of parentheses (as might sometimes occur)."
newStr := RegExReplace(str, "( \(|\()[^\)]*?\)")
MsgBox, % str "`n`n" newStr
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: How to delete the text of parentheses in a sentence
im learning regex, what is the reason for the |\( It looks to me like a repeat of what is before it. I tried it without it and it worked well, so im wondering what that extra OR \( does?boiler wrote: ↑15 Jan 2021, 04:28Code: Select all
str := "The solution should probably handle cases (like this one) with multiple pairs of parentheses (as might sometimes occur)." newStr := RegExReplace(str, "( \(|\()[^\)]*?\)") MsgBox, % str "`n`n" newStr
EDIT: I think I figured it out, the first one covers a ( proceeded by a space and the second one doesnt?
Code: Select all
str := "The solution should probably handle cases (like this one) with multiple pairs of parentheses (as might sometimes occur)."
newStr := RegExReplace(str, "( \()[^\)]*?\)")
MsgBox, % str "`n`n" newStr
Re: How to delete the text of parentheses in a sentence
That is correct.AHKStudent wrote: ↑15 Jan 2021, 04:35what is the reason for the |\( It looks to me like a repeat of what is before it. I tried it without it and it worked well, so im wondering what that extra OR \( does?
EDIT: I think I figured it out, the first one covers a ( proceeded by a space and the second one doesnt?
Code: Select all
str := "It handles cases where no space precedes the open parenthesis(just in case)."
newStr := RegExReplace(str, "( \(|\()[^\)]*?\)")
MsgBox, % str "`n`n" newStr
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: How to delete the text of parentheses in a sentence
Thank youboiler wrote: ↑15 Jan 2021, 04:42That is correct.AHKStudent wrote: ↑15 Jan 2021, 04:35what is the reason for the |\( It looks to me like a repeat of what is before it. I tried it without it and it worked well, so im wondering what that extra OR \( does?
EDIT: I think I figured it out, the first one covers a ( proceeded by a space and the second one doesnt?Code: Select all
str := "It handles cases where no space precedes the open parenthesis(just in case)." newStr := RegExReplace(str, "( \(|\()[^\)]*?\)") MsgBox, % str "`n`n" newStr
Re: How to delete the text of parentheses in a sentence
You're amazingboiler wrote: ↑14 Jan 2021, 03:57Code: Select all
str := "Absorb and integrate (people, ideas, or culture) into a wider society or culture." newStr := RegExReplace(str, "( \(|\()[^\)]*?\)") MsgBox, % str "`n`n" newStr
Re: How to delete the text of parentheses in a sentence
Thank you, much appreciatedsofista wrote: ↑14 Jan 2021, 07:42As BoBo suggested,
Code: Select all
str := "Absorb and integrate (people, ideas, or culture) into a wider society or culture." newStr := StrSplit(str, [" (", ")"]) MsgBox, % str "`n`n" newStr[1] newStr[3]
Re: How to delete the text of parentheses in a sentence
Thank you, much appreciatedChunjee wrote: ↑14 Jan 2021, 16:13dirty:Code: Select all
A := new biga() ; requires https://www.npmjs.com/package/biga.ahk string := "Absorb and integrate (people, ideas, or culture) into a wider society or culture." msgbox, % A.replace(string, "/\(.+\) /", "") ; => "Absorb and integrate into a wider society or culture."