T
First of all, you have to be very careful with expressions like
you're trying, where a coincidence .+ can match
with the same as the next with.+as they are the typical example of
a regular expression that generates a catastrophic backtracking. That's it.
I mean, never use that expression. More information in
https://www.regular-expressions.info/catastrophic.html It can be solved in 3 ways, depending on the degree of complexity. From simpler to more complex:1. Text between simple quotesNow, for the quotes not to enter into the capture of a group, they must be put out. And, within the group, we can look to match any character other than a quote: [^']*.Regular expression:asignarValores\('([^']*)', '([^']*)', '([^']*)', '([^']*)', '([^']*)', '([^']*)', '([^']*)'\)
http://fiddle.re/yyyyy8g4t4d (click on Java).If you really prefer regex101, https://regex101.com/r/Stu3FZ/1 , but you have to keep in mind that regex101 does not use the same regex engine as Java.This is the simplest and most efficient way to match text between quotes (-although it serves for other cases, really, you don't even think to use .*? here).2. Comillas escaped inside the quotation marksIf simple quotation marks are allowed \' within a parameter, then we have to match all characters that are not \ and ', and then allow to match a bar followed by any character (\.). I mean, for each parameter we would use:'([^'\]*(?:\\.[^'\]*)*)'
While there are more matched patterns for this very thing, this is the most efficient way to do it, using a technique called http://www.softec.lu/site/RegularExpressions/UnrollingTheLoop .Regex repeating this structure for the 7 parameters:asignarValores\('([^'\]*(?:\\.[^'\]*)*)', '([^'\]*(?:\\.[^'\]*)*)', '([^'\]*(?:\\.[^'\]*)*)', '([^'\]*(?:\\.[^'\]*)*)', '([^'\]*(?:\\.[^'\]*)*)', '([^'\]*(?:\\.[^'\]*)*)', '([^'\]*(?:\\.[^'\]*)*)'\)
http://fiddle.re/yyyyy4fnz6r (click on Java).Or https://regex101.com/r/Stu3FZ/2 .3. Single quotes or double quotesIf you want to allow yourself so much ' Like " for each parameter, then we modify it a little to match the 2 options:(['"])([^'"\]*(?:(?:\\.|(?!\1)['"])[^'"\]*)*)\1
(['"]) ::: We keep the reference to the type of quotation marks opened in $1.([^'"\]*(?:(?:\\.|(?!\1)['"])[^'"\]*)*) ::: Capture content in $2:[^'"\]* ::: characters that are not ', "Neither \(?:(?:\\.|(?!\1)['"])[^'"\]*)* ::: One of the exceptions, followed by more text that is not quotes or bars, all of this as often as possible (repeated with *).Exceptions (?:\\.|(?!\1)['"]) are:\\. ::: a bar followed by any character, or(?!\1)['"] ::: if it is not followed by the table with which it was opened, a quote (i.e., if the text is in double quotation marks, which can coincide with simple quotation marks, and vice versa).\1 ::: Coincide with the same type of quotation marks opened.The complete regex remains:asignarValores\((['"])([^'"\]*(?:(?:\\.|(?!\1)['"])[^'"\]*)*)\1, (['"])([^'"\]*(?:(?:\\.|(?!\3)['"])[^'"\]*)*)\3, (['"])([^'"\]*(?:(?:\\.|(?!\5)['"])[^'"\]*)*)\5, (['"])([^'"\]*(?:(?:\\.|(?!\7)['"])[^'"\]*)*)\7, (['"])([^'"\]*(?:(?:\\.|(?!\9)['"])[^'"\]*)*)\9, (['"])([^'"\]*(?:(?:\\.|(?!\11)['"])[^'"\]*)*)\11, (['"])([^'"\]*(?:(?:\\.|(?!\13)['"])[^'"\]*)*)\13\)
Where we are only interested in catches created by pair groups (groups 1, 3, 5, ... we use them to capture the type of quotes). http://fiddle.re/yyyyyuj0b0d (click on Java).Or https://regex101.com/r/Stu3FZ/3 .