- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 01:29 AM
Hi Team,
i need to split the below sentence using regex, Please help me out in 2nd line of the code.
i want to include the symbols [,],| as delimiters. please suggest me.
gs.print(items[2])
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 02:38 AM
hi @Srvs
from your code Assuming urlify function is defined elsewhere
Please try like below
var finComment = 'test [Click Here|http://example.com]';
var htmlComment = finComment;
var sysIdList = htmlComment.match(/^(.*?)\s*\[(.*?)\|(.*?)\]$/);
if (sysIdList) {
var part1 = sysIdList[1];
var part2 = sysIdList[2];
var part3 = sysIdList[3];
var htmlOutput = part1 + '[code]<a href="' + part3 + '" target="_blank">' + part2 + '</a>[/code]';
gs.print(htmlOutput);
} else {
gs.print("No match found");
}
i am getting output as :
test[code]<a href="http://example.com" target="_blank">Click Here</a>[/code]
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 01:52 AM
Hi @Srvs
Please try below code
var data = "test comments [Click Hete|http://example.com]";
var matches = data.match(/^(.*?)\s*\[(.*?)\|(.*?)\]$/);
if (matches) {
var part1 = matches[1];
var part2 = matches[2];
var part3 = matches[3];
gs.print(part1);
gs.print(part2);
gs.print(part3);
} else {
gs.print("No match found");
}
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 02:24 AM
Hi Bhavya,
Thank you for prompt response. we need to put closed square braket "]"
in above code data field contains dynamic comments from user. i have converted your code like below,
its not working, please suggest me if did anything wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 02:35 AM
Hi @Bhavya11 ,
if i retun like below,
return part1+'[code]<a href="'+'"'+part3+'"'+'target="_blank">'+'LINK'+'</a>[/code]';
putput is coming like: testhttp://example.com][/code"target="_blank">LINK
expected is test http://example.com 'target="_blank">'+'LINK'+'</a>[/code]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 02:38 AM
hi @Srvs
from your code Assuming urlify function is defined elsewhere
Please try like below
var finComment = 'test [Click Here|http://example.com]';
var htmlComment = finComment;
var sysIdList = htmlComment.match(/^(.*?)\s*\[(.*?)\|(.*?)\]$/);
if (sysIdList) {
var part1 = sysIdList[1];
var part2 = sysIdList[2];
var part3 = sysIdList[3];
var htmlOutput = part1 + '[code]<a href="' + part3 + '" target="_blank">' + part2 + '</a>[/code]';
gs.print(htmlOutput);
} else {
gs.print("No match found");
}
i am getting output as :
test[code]<a href="http://example.com" target="_blank">Click Here</a>[/code]
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks,
BK