-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
  • 7,826
  • 3
  • 21
  • 56
0x45
  • 779
  • 3
  • 7
  • 26

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
  • 761,203
  • 64
  • 569
  • 643
  • 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,670
  • 4
  • 45
  • 69
-1

You must use the result of replaceAll:

xqueryFileContent = xqueryFileContent.replaceAll("(fn\\-bea:uuid\\(\\))", "0");
Maurice Perry
  • 9,261
  • 2
  • 12
  • 24