Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Not applicable

Replacing Text using Wildcards?

Hey everyone,

I searched the Internet for my problem, but didn't find an appropriate solution.

What I want to do is to replace all "<*>" (* = Wildcard) in a string.

For example, I have this string: <p>Bauers <strong>"Auto-Zeitung"</strong> erscheint zusätzlich als Pocket-Ausgabe. Die Aktion ist allerdings auf eine Ausgabe beschränkt, denn die Mini-Version dient vor allem einem Werbekonzept für das neue <strong>Volkswagen</strong>-Modell Up.</p>

And I want it to become this: Bauers "Auto-Zeitung" erscheint zusätzlich als Pocket-Ausgabe. Die Aktion ist allerdings auf eine Ausgabe beschränkt, denn die Mini-Version dient vor allem einem Werbekonzept für das neue Volkswagen-Modell Up.

Is it possible using the replace expression or is there another solution?

Thanks for help!

Regards

Daniel

1 Solution

Accepted Solutions
MVP
MVP

Replacing Text using Wildcards?

Hm, try this:

function removeTags(rawHTML)

   Dim objRegExp, strOutput

  Set objRegExp = New Regexp

  objRegExp.IgnoreCase = True

  objRegExp.Global = True

  objRegExp.Pattern = "<[^>]*>"

  'Replace all HTML tag matches with the empty string

  strOutput = objRegExp.Replace(rawHTML, "")

 

   removeTags = strOutput    'Return the value of strOutput

  Set objRegExp = Nothing

End Function

6 Replies
mov
Esteemed Contributor III

Replacing Text using Wildcards?

Daniel,

No wildcards, in replace, as far as I know..

This one is probably not the best solution, but it should work:

=textbetween(YourTextField, '>','<', 1) & ' ' &

textbetween(YourTextField, '>','<', 2) &  ' ' &

textbetween(YourTextField, '>','<', 3) & ' ' &

...

MVP
MVP

Re: Replacing Text using Wildcards?

Hi Daniel,

I suggest that you use a macro function that will make use of regular expressions to remove the tags, like a JScript

function removeTags(rawText) {

return rawText.replace(/<[^>]*>/gi, "");

}

and then call this function in your load script.

Please see attached.

Regards,

Stefan

Not applicable

Re: Replacing Text using Wildcards?

Hi Stefan,

this sounds really good and thanks for the help so far. Do you know an appropriate function for VBscript? Or does this only work with JScript?

Regards,

Daniel

MVP
MVP

Replacing Text using Wildcards?

Hm, try this:

function removeTags(rawHTML)

   Dim objRegExp, strOutput

  Set objRegExp = New Regexp

  objRegExp.IgnoreCase = True

  objRegExp.Global = True

  objRegExp.Pattern = "<[^>]*>"

  'Replace all HTML tag matches with the empty string

  strOutput = objRegExp.Replace(rawHTML, "")

 

   removeTags = strOutput    'Return the value of strOutput

  Set objRegExp = Nothing

End Function

Not applicable

Re: Replacing Text using Wildcards?

Many thanks!! I would have never figured that out!

Have to remember this

ronalddoes
Contributor III

Re: Replacing Text using Wildcards?

Hi Stefan,

Your function appears to age well, it helped me out great today!

I've improved the RegEx-pattern a bit to also exclude &nsbp;-like tags from the source.

function removeTags(rawHTML)

  Dim objRegExp, strOutput

  Set objRegExp = New Regexp

  objRegExp.IgnoreCase = True

  objRegExp.Global = True

  objRegExp.Pattern = "<[^>]*>|&[^>]*;"

  'Replace all HTML tag matches with the empty string

  strOutput = objRegExp.Replace(rawHTML, "")

  removeTags = strOutput    'Return the value of strOutput

  Set objRegExp = Nothing

End Function

Thanks!