Skip to main content
edited title
Link
identigral
  • 7.8k
  • 34
  • 33
  • 45

Struggling with Pattern.matches - searching an entire string vs a substring

Became Hot Network Question
added 21 characters in body; edited title
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

Strugiling Struggling with Pattern.matches

This RegExpMy regular expression is working properly here: https://regexr.com/4j143

However, when I try to use it in Apex it is not working:

String regExp = '/\\s{1,}(ORDER BY)\\s{1,}(ID)(\\s{1,}(ASC)){0,1}(\\s{1,}(NULLS)\\s{1,}(LAST)){0,1}\\s{0,},/gi';
String input = 'SELECT * FROM ... ORDER BY ID, INDUSTRY ASC';

System.debug(Pattern.matches(regExp, input));

Can somebody spot my mistakeWhat am I doing wrong? How do I fix it?

Strugiling with Pattern.matches

This RegExp is working properly here: https://regexr.com/4j143

However, when I try to use it in Apex it is not working:

String regExp = '/\\s{1,}(ORDER BY)\\s{1,}(ID)(\\s{1,}(ASC)){0,1}(\\s{1,}(NULLS)\\s{1,}(LAST)){0,1}\\s{0,},/gi';
String input = 'SELECT * FROM ... ORDER BY ID, INDUSTRY ASC';

System.debug(Pattern.matches(regExp, input));

Can somebody spot my mistake?

Struggling with Pattern.matches

My regular expression is working properly here: https://regexr.com/4j143

However, when I try to use it in Apex it is not working:

String regExp = '/\\s{1,}(ORDER BY)\\s{1,}(ID)(\\s{1,}(ASC)){0,1}(\\s{1,}(NULLS)\\s{1,}(LAST)){0,1}\\s{0,},/gi';
String input = 'SELECT * FROM ... ORDER BY ID, INDUSTRY ASC';

System.debug(Pattern.matches(regExp, input));

What am I doing wrong? How do I fix it?

Source Link
Saulo
  • 987
  • 1
  • 8
  • 26

Strugiling with Pattern.matches

This RegExp is working properly here: https://regexr.com/4j143

However, when I try to use it in Apex it is not working:

String regExp = '/\\s{1,}(ORDER BY)\\s{1,}(ID)(\\s{1,}(ASC)){0,1}(\\s{1,}(NULLS)\\s{1,}(LAST)){0,1}\\s{0,},/gi';
String input = 'SELECT * FROM ... ORDER BY ID, INDUSTRY ASC';

System.debug(Pattern.matches(regExp, input));

Can somebody spot my mistake?