I've got a text which has some HTML tags in it. Something like this:
Lorem lipsum <a href="www.example.com"> lorem lipsum.
I want to insert the text style=\"text-decoration: none\ right at the end of the HTML tag so that the link has no underline.
I've got a regex pattern that finds the HTML tag: <\s*a[^>]*>(.*?)<\s*/\s*a>
I have the following code to get the regex matches in the paragraph text and to calculate the position of the last character in the HTML tag:
let range = NSRange(location: 0, length: paragraph.utf16.count)
let regex = try! NSRegularExpression(pattern: "<\\s*a[^>]*>(.*?)<\\s*/\\s*a>")
let allMatches = regex.matches(in: paragraph, options: [], range: range)
let lastCharacter = allMatches[0].range.location + allMatches[0].range.length
How can I insert the string style=\"text-decoration: none\ at that position?
I tried something like this:
let newParagraph = paragraph.insert(" style=\"text-decoration: none\"", at: lastCharacter)
However Xcode says that the first parameter in the insert method has to be a character, not a string.