-1

I've built the following regex. This matches the function call fn-bea:uuid()

It obviously matches the function, but when integrating it into my java program:

xqueryFileContent.replaceAll("(fn\\-bea:uuid\\(\\))", "0");

the function is not replaced. Any ideas what I'm missing?

kutschkem
  • 6,987
  • 3
  • 17
  • 48
0x45
  • 669
  • 3
  • 7
  • 24

3 Answers3

2

There is no need to use a regex here. Just String#replace for simple string search-replace:

xqueryFileContent = xqueryFileContent.replace("fn-bea:uuid()", "0");

If you must use a regex then use Pattern.quote to quote all special characters:

xqueryFileContent = xqueryFileContent.replaceAll( 
  Pattern.quote("fn-bea:uuid()"), "0" ); 
anubhava
  • 713,503
  • 59
  • 514
  • 593
  • In this testcase there's just one fn-bea:uuid(), but there can be multiple. replaceAll wants a pattern as parameter. – 0x45 Mar 23 '18 at 10:17
-1

You don't need to escape your - :

xqueryFileContent.replaceAll("(fn-bea:uuid\\(\\))", "0");
Zenoo
  • 12,242
  • 4
  • 44
  • 63
-1

You must use the result of replaceAll:

xqueryFileContent = xqueryFileContent.replaceAll("(fn\\-bea:uuid\\(\\))", "0");
Maurice Perry
  • 8,497
  • 2
  • 10
  • 23