
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 07:55 AM
I'm needing to update the names of some assets and CIs by removing some ending characters. I need to look for ' - ' (that's space - space) and then remove the ' - ' plus the characters after that.
Have not had to do this before, still looking into it. Thanks in advance for the assistance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:03 AM
Hi David,
You can do this by regEx and replace. Here is an example you can test and reuse pretty much:
var test = 'goran - remove this';
gs.debug(test.replace(/\s[-]\s.*/, ''));
//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:25 AM
Hi David,
regular expression should work fine when you know the pattern would match everytime
I would recommend string manipulation for simpler cases
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 09:43 AM
I would say both works without any specific Pros/Cons. Just a matter of personal preference, I think. So use what you feel most comfortable using. I would recommend learning RegEx for future cases since it can be powerful, and you will probably have a requirement in the future that RegEx is the solution for the requirement.
I'm no expert in RegEx, but when I started, I began with Chucks, both videos about it. I can't find them right now, but I bet
//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 06:35 AM
TechNow Episodes 31 and 32 on Regular Expressions can be found on the master list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 06:56 AM
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2023 07:32 PM
Can I modify this one to have a set end string?
Values in between will change.
?version and api will be the constant
original - ?version=1&modificationDate=1412296476867&api
Desired - ?api