Convert user input string to Regex

Ky-Anh Huynh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 16 03:18:31 UTC 2017


Hi,

Is there a way to transform user input string to a regular 
expression? For example, I want to write a `grep`-like program

```
mygrep -E '/pattern/i' file.txt
```

and here the user's parameter `/pattern/i` would be converted to 
a Regex object.

Fyi, in Ruby, `to_regexp` is a useful gem: 
https://rubygems.org/gems/to_regexp

Thanks a lot.


More information about the Digitalmars-d-learn mailing list