You need to sign in to do that
Don't have an account?
Trif Cristian 7
replaceAll method doesn't work how it want
Hi, I have the following text:
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
I want to replace all the `<br>`with the new line `\n`.
So I used this function:
target = target.replaceAll('<br>', '\n'); but I have this error: Error on line 38, column 1: System.StringException: No match found. And if I try to replace with another string for example:
target = target.replaceAll('<br>', 'test'); It works like a charm...
Here it's the full code for this:
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
I want to replace all the `<br>`with the new line `\n`.
So I used this function:
target = target.replaceAll('<br>', '\n'); but I have this error: Error on line 38, column 1: System.StringException: No match found. And if I try to replace with another string for example:
target = target.replaceAll('<br>', 'test'); It works like a charm...
Here it's the full code for this:
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?'; target = target.replaceAll('<br>', '\n'); String regExp = '(.*)'; Pattern myPattern = Pattern.compile(regExp); Matcher myMatcher = myPattern.matcher(target); System.debug('Matches: ' + myMatcher.matches()); System.debug('Group 0: ' + myMatcher.group(1));
you can use the following code
Hi Newbie,
It shows correctly in the debug but I still have this error:
"Error on line 38, column 1: System.StringException: No match found."
You know why?
Ignore the commented code.:D
target = target.replace('<br>', '\\n');
replace '\n' to '\\n'
if this works let know pls
@vinaykumar
I tried like this also.. does not work.
I tried like this also: target = target.replaceAll('<br>', 'test'); and it works... apparently only \n does not like it. :D
code :
String target = '<br><br>I love computers and I love to program. <br>Do you love to program? <br><br>Or not?';
target = target.replace('<br>', '\\n');
String regExp = '(.*)';
Pattern myPattern = Pattern.compile(regExp);
Matcher myMatcher = myPattern.matcher(target);
System.debug('Group 0: ' + myMatcher);
System.debug('Group 0: ' + myPattern);
System.debug('Matches: ' + myMatcher.matches());
System.debug('Group 0: ' + myMatcher.group(0));
output: