-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?

3
  • I can't make out if \\- is escaping - or if you want to match \-. Please clarify it by giving the exact string to replace it. Commented Mar 23, 2018 at 10:11
  • @ArunGowdru I want to replace fn-bea:uuid() with 0 Commented Mar 23, 2018 at 10:12
  • 1
    You need to assign the replaced value back to xqueryFileContent Commented Mar 23, 2018 at 10:22

3 Answers 3

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" ); 
Sign up to request clarification or add additional context in comments.

1 Comment

In this testcase there's just one fn-bea:uuid(), but there can be multiple. replaceAll wants a pattern as parameter.
-1

You don't need to escape your - :

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

5 Comments

Not working, and why do I need to double escape, single escape of \` would also return \` no?
@0x45 I updated my answer, I thought you wanted to match a backslash.
@0x45 Are you reassigning your Java variable? xqueryFileContent = xqueryFileContent.replaceAll("(fn-bea:uuid\\(\\))", "0");
- is a special character for regex, yes it needs escaping
@kutschkem Inside [] yes, not outside
-1

You must use the result of replaceAll:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.