Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-1003] NSRegularExpressionOptions.AnchorsMatchLines ignored #4365

Closed
swift-ci opened this issue Mar 21, 2016 · 4 comments
Closed

[SR-1003] NSRegularExpressionOptions.AnchorsMatchLines ignored #4365

swift-ci opened this issue Mar 21, 2016 · 4 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-1003
Radar None
Original Reporter swift-studies (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Ubuntu 15.10

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Linux
Assignee @pushkarnk
Priority Medium

md5: 0292be96ae89e0648973a601f0bf1ce6

Issue Description:

The following code example only matches once on Linux, but works as expected on OS X

import Foundation

let text = " * Item 1\n * Item 2\n * Item 3\n * Item 4\n * Item 5\n * Item 6\n"

let pattern = "(\\n)?(^[ \\t]*)([*-])[ \\t]+((?s:.+?)(\\n{1,2}))(?=\\n*(\\z|\\2([*-])[ \\t]+))"

if let regex = try? NSRegularExpression(pattern:pattern,options:[NSRegularExpressionOptions.AnchorsMatchLines]){
        //Template replacement
        var mutableString = NSMutableString(string:text)

        regex.replaceMatchesInString(mutableString, options: NSMatchingOptions(), range: NSMakeRange(0,text.characters.count), withTemplate: "Matched: $4")
    
        //Print result
        print(mutableString)
}

Expected output is

Matched: Item 1
Matched: Item 2
Matched: Item 3
Matched: Item 4
Matched: Item 5
Matched: Item 6

But on Linux the template is only applied once (same is true when enumerating with blocks only one match is returned)

Matched: Item 1
 * Item 2
 * Item 3
 * Item 4
 * Item 5
 * Item 6

Example on IBM Swift Sandbox

@pushkarnk
Copy link
Collaborator

I have been doing some other work on NSRegularExpression and can take a look at this as well.

@swift-ci
Copy link
Contributor Author

Comment by Swift Studies (JIRA)

Great!

@pushkarnk
Copy link
Collaborator

PR created: #301

@pushkarnk
Copy link
Collaborator

PR merged

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants