Hello Everyone,
I've been trying to clear a string from the HTML tags contained in it. Below is the code, I tried:
var oRegExp = new RegExp('/\/?[^>]+(>|$)/', 'g'); retrievedExtDesc = retrievedExtDesc.replace(oRegExp, '');
But this is the error, I get:
I tried using double quotation marks also. I tried removing the single quotation mark from the letter g in the RegExp constructor, but that did not help - I get another error - g not recognised or something, if I do that.
I'd appreciate any suggestions. Thanks!
i found a similar problem in the forum. i'll try to use regex, but there is not easy.
bye
The error message tells you that you are trying to mix Java and Javascript
It tells you that you are trying to use the Java method java.lang.String.replace and as arguments you want to give it two arguments that are only acceptable in Javascript methods.
You probably assumed that something like
objectDefinitionObject.Attribute(Constants.AT_DESC, nLocale).getHTMLFormattedValue().getHTML();
would return you a Javascript string, for which you could use the Javascript .replace function. Nah, that's not how this works. Go to your ARIS Script help, open the webpage for the .getHMTL() method and click on the link of the returned object type. It will bring you to the Java API documentation, meaning you get a Java String as a returned value.
What to do now you may ask? Well Java Strings have a method called replaceAll and it's used like this:
var descHTMLString = selDef.Attribute(Constants.AT_DESC, nLocale).getHTMLFormattedValue().getHTML(); var filterdString = descHTMLString.replaceAll("<.*?>", "");
The regular expression is pretty simple
- Look for strings that start with <
- after that match any character as few times as you can
- until you find a >
With replaceAll you can find many individual matches in your given html String, and replace them with empty strings, leaving behind just the thing that wasn't enclosed in < >.