Matt
Matt

Reputation: 426

Regular expression, ignore specific characters from second group

I have the following regular expression \[([^]]*)] ([^]]*) I use it to separate a string like [text] message to send! into text as a type and message to send! as the message, I use it so it's easier to change the type of messages to send. It works really well but I encountered a problem, if the message contains [ ] it ends the expression for example: [text] message to send as a [test] anything after this is ignored! it would process text as group one and only [text] message to send as a [test as group two.
How can I make it so the group two is anything after the first [ ] is found, ignoring what ever is after and putting it on group two?

Example: https://regex101.com/r/mXDReg/2

Upvotes: 0

Views: 105

Answers (1)

karthick
karthick

Reputation: 12176

You are already matching the first group if all you want to do is match the rest then simply change the regex from

\[([^]]*)] ([^]]*)

to

\[([^]]*)](.*)

Upvotes: 1

Related Questions