https://kotlinlang.org logo
m

muliyul

01/13/2021, 12:22 AM
Hey everyone this is not really related to Kotlin but I need help. I have an HTML I'd like to replace a portion of it (a json object) with my json. the markup looks like this
Copy code
[html...] SwaggerUIBundle({ ... }) // the object I'm trying to replace is the parameter to this factory
[...html]
The object may have indentation, new lines etc. I came up with this:
Copy code
html.replace("""\s*\{(\s*.*)*}\s*?""".toRegex(), myJsonFormattedString)
But since the expression resides between js brackets the regex is matching all the way to the closing bracket for example:
Copy code
{ ... }) [...javascript] }
I tried to use the non-greedy modifier but it didn't seem to work. Your help is appreciated!