I wonder how one converts a string into a real regex... if I try something like: var sRegex=userinput.value var sResult = sSomestring.replace(sRegex, "xxx"); the sRegex is interpreted as a string and not as a real /regex/ How can I change this so the user can enter a regex and have it interpreted? I guess this requires some kind of cast but to what kind of objectype?
![]() |
-1 |
![]() |
On 14 Aug 2003 08:11:32 -0700, paulgiverny@hotmail.com (Phil) wrote: >I wonder how one converts a string into a real regex... > >if I try something like: > >var sRegex=userinput.value >var sResult = sSomestring.replace(sRegex, "xxx"); > >the sRegex is interpreted as a string and not as a real /regex/ new RegExp(sRegex) Jim. -- comp.lang.javascript FAQ - http://jibbering.com/faq/
![]() |
-1 |
![]() |
Phil wrote: > I wonder how one converts a string into a real regex... > > if I try something like: > > var sRegex=userinput.value var rexExp = new RegExp(userinput.value) > var sResult = sSomestring.replace(sRegex, "xxx"); > > the sRegex is interpreted as a string and not as a real /regex/ > > How can I change this so the user can enter a regex and have it interpreted? > > I guess this requires some kind of cast but to what kind of objectype? -- Martin Honnen http://JavaScript.FAQTs.com/
![]() |
1 |
![]() |