Swift Regex: Beyond the basics

RSS for tag

Discuss the WWDC22 Session Swift Regex: Beyond the basics

Posts under wwdc2022-110358 tag

3 Posts
Sort by:
Post not yet marked as solved
0 Replies
60 Views
Code to reproduce: let inputString = "url(https://example.com)" let regex = Regex {   "url("   Capture {     .url()   }   ")" } guard let (_, url) = inputString.firstMatch(of: regex)?.output else {   fatalError() } print(url) Regex matches if we change "url(" to "(": let regex = Regex {   "("   Capture {     .url()   }   ")" } However, the output is Is this a bug?
Posted
by auriaiur.
Last updated
.
Post not yet marked as solved
0 Replies
122 Views
Feedback is filed. Trying to look into the Core.swift. diagnostics: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:  ---------------------------------------- CrashReportError: Fatal Error in Core.swift UtilityScript crashed due to fatalError in Core.swift at line 77. 'try!' expression unexpectedly raised an error: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:  ))' Process: UtilityScript[3141] Date/Time: 2022-07-02 03:56:17 +0000 Log File: <none> Application Specific Information:     dyld [         dyld config: DYLD_LIBRARY_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/UtilityScript-frovasvohxblobefzbrrwtvqtyuu/Build/Intermediates.noindex/Previews/UtilityScript/Products/Debug DYLD_FRAMEWORK_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/UtilityScript-frovasvohxblobefzbrrwtvqtyuu/Build/Intermediates.noindex/Previews/UtilityScript/Products/Debug     ]     libswiftCore.dylib [         _StringProcessing/Core.swift:77: Fatal error: 'try!' expression unexpectedly raised an error: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:  ))'         /AppleInternal/Library/BuildRoots/0cc5e7ad-e86f-11ec-ac50-3e2aa58faa6a/Library/Caches/com.apple.xbs/Sources/swiftlang_overlay_Platform/swift-experimental-string-processing/Sources/_StringProcessing/ConsumerInterface.swift:200     ]
Posted Last updated
.
Post not yet marked as solved
1 Replies
168 Views
Version 14.0 beta (14A5228q) I'm getting errors when using the sample code at [3:49], in a playground. The code is below. The line with the .split throws an error, as does the switch statement. If the parameter named "separator" is replaced with "by", then the line works. Unable to fine a way to get the switch to work. let input = "name: John Appleseed, user_id: 100" let regex = /user_id:\s*(\d+)/ input.firstMatch(of: regex) // Regex.Match<(Substring, Substring)> input.wholeMatch(of: regex) // nil input.prefixMatch(of: regex) // nil input.starts(with: regex) // false input.replacing(regex, with: "456") // "name: John Appleseed, 456" input.trimmingPrefix(regex) // "name: John Appleseed, user_id: 100" input.split(separator: /\s*,\s*/) // ["name: John Appleseed", "user_id: 100"] switch "abc" { case /\w+/: print("It's a word!") }
Posted
by lrettberg.
Last updated
.