Peekmo
Peekmo

Reputation: 2903

Regex : One single character between 2 chars

I searched a lot, but never found an answer to my question, and I'm desperate.

I would like to get all dots ( '.' ) between parenthesis wherever they are, and with and undefined number of parenthesis. The problem is that I can just get the first dot, but I don't know how to get all in the same group.

I tried this : \((?:[^\.]*)([\.])(?:[^\.]*)*\)

But it just works if there's just one dot.. Any idea please ?

Upvotes: 3

Views: 101

Answers (2)

l'L'l
l'L'l

Reputation: 47169

Try this:

(\(|(\.)|\))

example: http://regex101.com/r/jV5yI0

Upvotes: 4

JaredPar
JaredPar

Reputation: 754753

Part of the reason you're having problems finding an answer to this is that there really isn't one. In order to match an arbitrary number of parenethesis, or any other construct that, that requires a context free grammar. A regex simply isn't powerful enough

That being said there are some Regex engines out there that do support this type of matching. The support tends to be very Engine specific though (for example .Net does it with balancing groups). If you can tell us what engine you are using we may be able to provide an exact answer here

Upvotes: 0

Related Questions