Without introducing the g (global flag), the regular expression will match at most a single occurrence. This is equivalent to the plain replace call like 'sdtmig-3-1-2'.replace('-', '/')
which results in "sdtmig/3-1-2"
.
Please see a plain regular expression usage (make sure the global modifier is turned off and use /-/ regular expression with a substitution of /).
For example:
console.log('sdtmig-3-1-2'.replace(/-/, '/'));
With the global flag, it would replace all the occurrences:
console.log('sdtmig-3-1-2'.replace(/-/g, '/'));
You can also use lazy prefix match of anything before the first occurrence and replace the matched groups with their original contents so they wrap around the replaced character. Please see the regular expression for this:
(.*?)-(.*) and a substitution of $1/$2.
This should work with XQuery replace function.
console.log('sdtmig-3-1-2'.replace(/(.*?)-(.*)/, '$1/$2'));