# Regular expression test

**URL:** <https://forum.kirupa.com/t/regular-expression-test/314181>\
**Category:** flash\
**Created:** [September 21, 2010, 3:26am UTC](https://forum.kirupa.com/t/regular-expression-test/314181 "2010-09-21T03:26:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aviar](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@Aviar](https://forum.kirupa.com/u/Aviar)\
**Post date:** [September 21, 2010, 3:26am UTC](https://forum.kirupa.com/t/regular-expression-test/314181/1 "2010-09-21T03:26:58Z")

</div>

I am creating a simple application and wanted to use a function to match any given regular expression to any given string, so I created the following function:

```php
function validateStr(regexp:RegExp, strVal:String):Boolean{
   if(regexp.exec(strVal)==null)
      return false;
   else
      return true;
}

```

But I was wondering, can’t I simply replace it with

```php
function validateStr(regexp:RegExp, strVal:String):Boolean{
   return regexp.test(strVal);
}

```

I am relatively new to ActionScript, so I do not know if both would present the same behavior.
