File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1
1
use opener;
2
2
use rand:: seq:: SliceRandom ;
3
+ use regex:: Regex ;
3
4
use std:: collections:: HashMap ;
4
5
use std:: env;
5
6
use std:: fs:: { self , File } ;
@@ -514,6 +515,36 @@ impl Executor {
514
515
self . stack . push ( Type :: Bool ( text. contains ( & word) ) )
515
516
}
516
517
518
+ // 正規表現で検索
519
+ "regex" => {
520
+ let pt = self . pop_stack ( ) . get_string ( ) ;
521
+ let patern: Regex ;
522
+ match Regex :: new ( pt. as_str ( ) ) {
523
+ Ok ( i) => patern = i,
524
+ Err ( _) => {
525
+ self . log_print ( "エラー! 正規表現が不正です\n " . to_string ( ) ) ;
526
+ return ;
527
+ }
528
+ }
529
+
530
+ let text = self . pop_stack ( ) . get_string ( ) ;
531
+
532
+ let value;
533
+ match patern. captures ( text. as_str ( ) ) {
534
+ Some ( i) => value = i,
535
+ None => {
536
+ self . stack . push ( Type :: List ( vec ! [ ] ) ) ;
537
+ return ;
538
+ }
539
+ }
540
+
541
+ let mut list: Vec < Type > = Vec :: new ( ) ;
542
+ for i in 0 ..value. len ( ) - 1 {
543
+ list. push ( Type :: String ( value. at ( i) . unwrap_or ( "" ) . to_string ( ) ) )
544
+ }
545
+ self . stack . push ( Type :: List ( list) ) ;
546
+ }
547
+
517
548
// 入出力コマンド
518
549
519
550
// ファイル書き込み
You can’t perform that action at this time.
0 commit comments