Menu

RegExp

Help
2006-11-02
2013-04-17
  • Duncan Beevers

    Duncan Beevers - 2006-11-02

    I feel as though I must be missing something obvious here.

    I'm trying to use the RegExp class to do very basic text replacement:

    import org.as2lib.regexp.Pattern;
    import org.as2lib.regexp.Matcher;

      public function Sanitize(content:String):String
      {
        var filter_expression:String = "<.*?>";
        var filter_pattern:Pattern = new Pattern(filter_expression);
        var matcher:Matcher = new Matcher(filter_pattern, content);
        return matcher.replaceAll("");
      }

    Everything compiles smoothly, but the output is difficult to understand.

    For example,

    Sanitize("apples"); returns "apples"
    Sanitize("apples<oranges>"); returns null

    What am I missing?

     
    • Ben Ford

      Ben Ford - 2008-06-30

      It seems like this forum is dead.

      I am stuck using Actionscript 2.0 and don't have any other way to perform regular expressions.

      Here is my working example:

      import org.as2lib.regexp.Pattern;
      import org.as2lib.regexp.Matcher;

      var someText = "helloWorld1";

      var pattern:Pattern = new Pattern("\\w+(\\d)");
      var matcher:Matcher = new Matcher(pattern, someText );

      label2.text = matcher.matches(); //returns "true"
      label3.text = matcher.getGroup(1); //returns "1"

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.