# Read regular expression from String

**URL:** <https://forum.kirupa.com/t/read-regular-expression-from-string/312866>\
**Category:** flash\
**Created:** [August 14, 2010, 12:46pm UTC](https://forum.kirupa.com/t/read-regular-expression-from-string/312866 "2010-08-14T12:46:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![92Garfield](https://avatars.discourse-cdn.com/v4/letter/9/e56c9b/32.png) [@92Garfield](https://forum.kirupa.com/u/92Garfield)\
**Post date:** [August 14, 2010, 12:46pm UTC](https://forum.kirupa.com/t/read-regular-expression-from-string/312866/1 "2010-08-14T12:46:05Z")

</div>

I want the user to input a regular expression, which is then used.

I’m using following at the moment.

```php
var filterEx = new RegExp(filterTxt.text.split("/")[1], filterTxt.text.split("/")[2]);

```

filterTxt is a textbox, when traceing the pattern is seemingly correct, but i.e.:

/\d+/ does match several numbers, but not all like it doesnt match 10 or 11.  
/\d\d/ does match 10 or 11 but I’m not sure if it matches any 2 digit number.  
/10/ does match 10 too.

So I hope there is a better way from string to regex.
