是否可以从 Ruby 中的外部文件加载正则表达式?
我想从 Ruby 中的外部文件读取正则表达式。例如,我想替换一个大字符串,从文件中加载每个正则表达式并为每个正则表达式运行 gsub 。每个正则表达式在文件上由换行符分隔。
外部文件将是这样的:
engenharia d[ae] computação
ci[êe]ncias? d[ae] computação
可能吗?
I want to read regular expressions from a external file in Ruby. For example, I want to substitute a big string loading every regex from a file and running gsub for each. Each regex is separated by newlines on the file.
The external file would be like this:
engenharia d[ae] computação
ci[êe]ncias? d[ae] computação
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然!您只需使用
Regex.new "my string"
即可创建正则表达式。将其与读取文件放在一起:Sure! You can create a regex simply by using
Regex.new "my string"
. To put it together with reading a file: