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

Different replace behavior #76

Open
kiliankoe opened this issue Jan 3, 2022 · 0 comments
Open

Different replace behavior #76

kiliankoe opened this issue Jan 3, 2022 · 0 comments

Comments

@kiliankoe
Copy link

kiliankoe commented Jan 3, 2022

Hi,

I'm trying to remove the contents of a string matching the following regex: (\((?:[A-N]\d?(?:, )?)+\)).

The idea is to remove these allergen-notices from a string like this:

Frikadelle von Rind und Schwein (A, A1, C, I, J) mit Paprika-Zwiebelgemüse (J), dazu Spätzle (A, A1, C)

I tried the following:

let regex = Regex(#" (\((?:[A-N]\d?(?:, )?)+\))"#)
let title = oldTitle.replacingAll(matching: regex, with: "")

For some reason this leads to "Paprika-Zwiebelgemüse (J)" being turned into "Paprika-Zwiebelgemüs)" and not "Paprika-Zwiebelgemüse" as expected.

When I use the native String API (.replacingOccurrences(of: #" (\((?:[A-N]\d?(?:, )?)+\))"#, with: "", options: .regularExpression)), it works like it should.

Is this a bug in Regex or am I doing something wrong? This is on iOS in case that's relevant.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant