converting a string to regular expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swarnap
    New Member
    • Sep 2006
    • 15

    converting a string to regular expression

    I have to generate a regular expression dynamically to check the file extensions. The file extension types are stored in a model data which are are to be fetched in form of a string and set into an hidden variable.
    <input type="hidden" id="extension" value="exe|doc" >

    In javascript it is used as
    var ext = document.getEle mentById("exten sion").value;
    var regEx = /^.+\.(ext)$/i;

    This does not replace the ext value "exe|doc" in the regEx .

    If I'm using
    var regEx = "/^.+\.("+ext+")$/i;
    Then it is giving regEx = /^.+\.(exe|doc)$/i; but regEx is in string format.

    So it is not working with "path.search(re gEx) != -1"
    where path contains the name of the file.

    So can anyone tell me how to generate a regular expression dynamically or say convert a string to regular expression.
  • swarnap
    New Member
    • Sep 2006
    • 15

    #2
    reg ex help

    I want a regular expression such that it will not allow " and ' in a text.

    Comment

    • gchq
      New Member
      • Jan 2007
      • 96

      #3
      I assume you mean search and replace?

      I think what you want is:-

      s/and/ /g

      (the g is for 'global')

      Comment

      Working...