问题
For example:
[TEXT1,TEXT2,TEXT3]
my expression: [\[].*,.*[\]]
Finds strings with commas (in between brackets,) but I only want to explicitly match the comma that exists in the square brackets.
I need to replace the commas with spaces - but only in the square brackets.
I've tried [\[],[\]]
but that doesn't work -
\[(.*?)\]
will find the text in between as well - but I do not want the entire string.
Can anyone suggest what I need to do to just find commas in between the brackets?
回答1:
Find what:
(?:\[|(?!^)\G)[^,\]]*\K,
Replace with:
space
Break-down:
(?:\[|(?!^)\G)
Matches the opening[
or the end of last match(?!^)\G
.[^,\]]*
Consumes all chars until the next comma.\K
Tells the regex engine to discard what it has matched so far.,
Finally matches the comma.
回答2:
I know this is an old question but I was looking to solve this same issue and found a solution with this: ,(?=[^\[]*\])
I hope it helps someone who stumbles on this post! 🙂
Note: Using Text Wrangler instead of Notepad++
回答3:
Square brackets generally need to be escaped in regex, so something like
\[.*(,).*\]
could work - where the regex group #1 (which is the captured/replaceable part in other tools, I don't have notepad++) would be the single comma in brackets that you want.
回答4:
I used this:
(?<=[\[,])[^\],]*(,)
Regex101
来源:https://stackoverflow.com/questions/32893701/how-to-extract-commas-in-between-square-brackets-in-notepad