You need to sign in to do that
Don't have an account?
SFDC Learning
Regex Pattern is not working
Hi,
I am looking out for the regex match for the Exact string.
For Example The sentence is: Hi there is cow and cowis white.and i want to remove only 'cow' string.
String s2 = 'Hi there is cow and cowis white';
String strRegEx ='\\[cow]\\';
Pattern MyPattern = Pattern.compile(strRegEx);
Matcher MyMatcher = MyPattern.matcher(s2);
Boolean result = MyMatcher.find();
if(MyMatcher.find()) {
s2 = s2.replaceall(strRegEx, ' ');
}
It is not working and if it woking the result is retunrs is 'Hi there is and is white'. Basically i just want to ignore the substrings to be removed.
Thanks in advance.
I am looking out for the regex match for the Exact string.
For Example The sentence is: Hi there is cow and cowis white.and i want to remove only 'cow' string.
String s2 = 'Hi there is cow and cowis white';
String strRegEx ='\\[cow]\\';
Pattern MyPattern = Pattern.compile(strRegEx);
Matcher MyMatcher = MyPattern.matcher(s2);
Boolean result = MyMatcher.find();
if(MyMatcher.find()) {
s2 = s2.replaceall(strRegEx, ' ');
}
It is not working and if it woking the result is retunrs is 'Hi there is and is white'. Basically i just want to ignore the substrings to be removed.
Thanks in advance.
It is throwing error: Compile Error: Illegal string literal: Invalid string literal '(?:^|\W)cow(?:$|\W)'. Illegal character sequence \W' in string literal
Thanks