6 Replies Latest reply: Oct 30, 2017 5:55 AM by Ronald van der Does RSS

    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

        • Replacing Text using Wildcards?
          Michael Solomovich

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

          ...

          • Re: Replacing Text using Wildcards?
            Stefan Wühl

            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

              • 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

                  • Replacing Text using Wildcards?
                    Stefan Wühl

                    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

                      • Re: Replacing Text using Wildcards?

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

                         

                        Have to remember this

                        • Re: Replacing Text using Wildcards?
                          Ronald van der Does

                          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!