Timeline for Extract and manipulate the string with Regex in apex
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 14, 2021 at 12:42 | comment | added | sfdcfox♦ |
@SaurabhKulkarni The input isn't in your control, but you're literally writing code for this. You can do whatever you want to do with the input string before replacement. If you want, you could use <br> in the regular expression as well. You could even input.split('<br>') then do the transformation on each element.
|
|
May 14, 2021 at 12:29 | comment | added | Saurabh Kulkarni | Also to add more, I don't this $ would help as it is not end of string in my case. The string ends when the whole conversation is ended. The break is at <br>( 14s ) to identify that there is a new line or different user message is starting | |
May 14, 2021 at 12:25 | comment | added | Saurabh Kulkarni | Thanks for your response @sfdcfox Unfortunately, the input string is not in my control. I will have to identify the places where sequence is <br>( 14s ) and replace it with <br>\n( 14 s ) and once the replacements are done use the way you have mentioned. Does that sound right to you or is there a better way to do it one shot? Really appreciate your all help on this, mate! | |
May 14, 2021 at 11:34 | comment | added | sfdcfox♦ |
@SaurabhKulkarni $ should also match the end of string, even if it's not a newline. I suppose a quick workaround would be to just add a \n to the end of your string.
|
|
May 14, 2021 at 10:47 | comment | added | Saurabh Kulkarni |
@sfdcfox I have one small issue with it. My each message doesn't end with \n and it ends something like this in actual ( 12s ) Agent K: Test msg <br>( 14s ) Guest: Reply msg <br> some on next line <br>( 18s ) Agent K: New msg Hence I believe the last group (.+) that is looking until end of line need a change. Could you please suggest for that too? I tried few things but doesn't work well
|
|
May 14, 2021 at 8:59 | vote | accept | Saurabh Kulkarni | ||
May 14, 2021 at 8:58 | comment | added | Saurabh Kulkarni | @sfdcfox This is extremely helpful.. Thank you so much for this and especially breaking it down with explanation. It works like a charm! | |
May 13, 2021 at 18:23 | history | edited | sfdcfox♦ | CC BY-SA 4.0 |
added 257 characters in body
|
May 13, 2021 at 18:21 | comment | added | Adrian Larson♦ | Absolutely, I figured as much. | |
May 13, 2021 at 18:20 | comment | added | sfdcfox♦ | @AdrianLarson Fair, semantics are important in HTML, this was more a focus on the technique. | |
May 13, 2021 at 18:19 | comment | added | Adrian Larson♦ |
Possibly worth noting that <strong> should be preferred over <b> in most cases.
|
|
May 13, 2021 at 18:16 | history | answered | sfdcfox♦ | CC BY-SA 4.0 |