Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
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
swuehl
MVP
MVP

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

View solution in original post

6 Replies
Anonymous
Not applicable
Author

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) & ' ' &

...

swuehl
MVP
MVP

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
Author

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

swuehl
MVP
MVP

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
Author

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

Have to remember this

RonaldDoes
Partner - Creator III
Partner - Creator III

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!