I have following string:
@[A:B:C].[X:Y:Z].[P:Q:R] 1.C.3.s @[1:2:3].[2:0:0].[5dsh:cxcv:wew]
I want to extract sub-strings from these that are in following format:
@[anything here].[anything here].[anything here]
In above case the output sub-strings should be:
@[A:B:C].[X:Y:Z].[P:Q:R]
@[1:2:3].[2:0:0].[5dsh:cxcv:wew]
I have this regular expression that matches these sub-strings:
(@\w+|@(?:\[[^\]]+\]\.?)+)
To test this regular expression I am replacing these sub-strings with $
in this fiddle: http://jsfiddle.net/vfe50z0o/
There is no problem with the regular expression as it is working in this Regex101 demo: https://regex101.com/r/aH9nK5/1
But on JSFiddle it's not working.
This is JavaScript code:
function myFunction() {
var re = /(@\w+|@(?:\[[^\]]+\]\.?)+)/;
var str = 'wewe@[s].[s].[s]xvcv';
var subst = '$';
var result = str.replace(re, subst);
alert(result);
}