-
Notifications
You must be signed in to change notification settings - Fork 12
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
findall working incorrectly #5
Comments
Hi, thanks for reporting the issue. However, I think the library is working as it is suppose to be. Take a look at the documentation of this method:
which is not the same as that of Python's re.findall As well as the declaration of the method:
Swift is different from Python, because it is statically strongly-typed(which makes Swift a much faster and safer language). It is implemented as a function to return an array of Strings, and you can not expect it to return an array of tuples. If you do want to get the captured groups from it, try re.finditer to get all the MatchObjects then map them to tuples. Remember, PySwiftyRegex only serves to let you deal with Regex using Python's re interfaces which makes your code cleaner, but after all it is written in Swift, not Python, and there are occasions in which they do not behave exactly the same. |
Thanks for answer |
Oh i tried as you said, and a lot of other functions, the problem that |
@Arti3DPlayer try this
|
It returns: But should return: [nil, "239.00"] |
@Arti3DPlayer How did you write the regex string in Swift? It should be a little bit different from that of Python, and you might need to add some ''s |
it comes from web, in variable |
that might be the problem |
yes, but i printed it, and it looks like i showed |
If i did without
it doesn't work.. |
@Arti3DPlayer I have tried your regex, it seems to be a bug when matching string that contains multiple lines. I'll let you know after I fixed it |
maybe needed some flag ? |
@Arti3DPlayer You are definitely right, it's not a bug. Try this re.finditer("<div class=\"cl_price\">[\\s\\.\\w<>=\"$\\/]*\\$(\\d+.\\d+)", string, flags: [.DotMatchesLineSeparators]).map { $0.groups() } |
Is this work for you ? For me not... I tried a lot of flags |
Oh, i found solution on swift:
|
I figured out the reason. For the html string of your url, print(value.characters.count) // prints 5486
print((value as NSString).length) // prints 5585 this inconsistency produces incorrect result when I cast from NSRange to Swift's Range. I guess I would have to figure out why casting from String to NSString will change its length first. |
@Arti3DPlayer Now re.finditer(pattern, string).map { $0.groups() } will return the correct value. |
thanks a lot |
http://stackoverflow.com/questions/35466584/swift-regex-find-all?noredirect=1#comment58632890_35466584
Hi, have the following issue. Tried your library. But it returns incorrect results :(
The text was updated successfully, but these errors were encountered: