File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -105,3 +105,18 @@ PatternPatch::Patch.new(
105105```
106106
107107If the ` :binding ` parameter is not passed, ERB is not invoked.
108+
109+ #### Regular expressions with modifiers in YAML
110+
111+ The ` regexp ` field in a YAML file may be specified with or without slashes
112+ or a modifier:
113+
114+ ``` YAML
115+ regexp : ' ^X' # Results in /^X/
116+ ` ` `
117+
118+ ` ` ` YAML
119+ regexp : ' /^X/i' # Results in /^X/i
120+ ` ` `
121+
122+ Currently only the slash literal notation is supported in YAML.
Original file line number Diff line number Diff line change @@ -17,7 +17,23 @@ def from_yaml(path)
1717 # Adjust string fields from YAML
1818
1919 if hash [ :regexp ] . kind_of? String
20- hash [ :regexp ] = /#{ hash [ :regexp ] } /
20+ regexp_string = hash [ :regexp ]
21+ if ( matches = %r{^/(.+)/([imx]*)$} . match regexp_string )
22+ flags = 0
23+ if matches [ 2 ] =~ /i/
24+ flags |= Regexp ::IGNORECASE
25+ end
26+ if matches [ 2 ] =~ /x/
27+ flags |= Regexp ::EXTENDED
28+ end
29+ if matches [ 2 ] =~ /m/
30+ flags |= Regexp ::MULTILINE
31+ end
32+ hash [ :regexp ] = Regexp . new matches [ 1 ] , flags
33+ puts "Regexp from YAML: #{ hash [ :regexp ] . inspect } "
34+ else
35+ hash [ :regexp ] = /#{ regexp_string } /
36+ end
2137 end
2238
2339 if hash [ :mode ] . kind_of? String
Original file line number Diff line number Diff line change 11module PatternPatch
2- VERSION = "0.4.1 "
2+ VERSION = "0.5.0 "
33end
You can’t perform that action at this time.
0 commit comments