Is there any difference between regular expressions in Swift and JS?

Tell me, is there any difference in the description of regular expressions in languages Swift and JavaScript. Or regular expression is uniform and independent of the programming language?
June 8th 19 at 17:23
3 answers
June 8th 19 at 17:25
Solution
A unified formal language independent of the programming language, but there are different types of implementation.
Bullshit. - Benedict_Shiel commented on June 8th 19 at 17:28
, but there are different types of implementation. PCRE — a library that implements the regular expressions in Perl (with some differences). - sofia.Maggio commented on June 8th 19 at 17:31
Yes, and Python and c# different types of implementation programming languages.
The phrase "different types of realization" that sounds impressive ) - Benedict_Shiel commented on June 8th 19 at 17:34
I did not say that. I said for yourself regular expressions and their software implementation. And here the language - I don't know. - sofia.Maggio commented on June 8th 19 at 17:37
,
the default: is there any difference between a spoon and a fork?
expert: technically the same, but different type of implementation. - Benedict_Shiel commented on June 8th 19 at 17:40
probably not the right analogy ))) I asked the difference between a plug made of iron and plastic, will they skip the noodle is not the diameter ))) - Zachary commented on June 8th 19 at 17:43
strange comparison there.
There is a difference between posix regex in JS and posix regex in PHP/Perl/C+/...?

I think not. Perhaps worded the answer wrong, not everyone is clear. - sofia.Maggio commented on June 8th 19 at 17:46
want to know thoroughly, dig yourself. I know Python - so there are extensions of the syntax of regex, and not implemented one of the types of forward-checking is available, for example, in js.
Such is the Libertines. - Benedict_Shiel commented on June 8th 19 at 17:49
so dumb bad do posix subset ) - Benedict_Shiel commented on June 8th 19 at 17:52
see , so the difference can still be. Honestly I checked by writing code with the same expressions in JS and Swift the sandbox and slip into the same texts. Like the output, everything is the same, but I'll keep in mind that there may be a rake. - Zachary commented on June 8th 19 at 17:55
not in "style of Perl", but perl compatible regular expressions, which differ from what is now implemented in the latest version of Perl - Jeff28 commented on June 8th 19 at 17:58
extract from Wikipedia) - sofia.Maggio commented on June 8th 19 at 18:01
between posix regex in JS and posix regex in PHP/Perl/C+/...?

And since when does Perl even have posix regex?
What is a posix regex - there are several options - basic, extended, etc. - Jeff28 commented on June 8th 19 at 18:04
June 8th 19 at 17:27
Solution
As well, United and invincible - it is the context.
In swift some crooked PCRE.
I'm interested simple expressions, such as:
/[\s]+|[^\s]+/
/([^\s])
/\r\n/
/([\r\n]|.)*?<\/style>/

This is from the JavaScript code. And you want to use in Swift ) - Benedict_Shiel commented on June 8th 19 at 17:30
, well, try, at random - everything ) - sofia.Maggio commented on June 8th 19 at 17:33
no problems.

import Cocoa

// (1):
let pat = "\\b([a-z])\\.([a-z]{2,})@([a-z]+)\\.ac\\.uk\\b"
// (2):
let testStr = "x.wu@strath.ac.uk, ak123@hotmail.com e1s59@oxford.ac.uk, ee123@cooleng.co.uk, a.khan@surrey.ac.uk"
// (3):
let regex = try! NSRegularExpression(pattern: pat, options: [])
// (4):
let matches = regex.matchesInString(testStr, 'options': [], range: NSRange(location: 0, length: testStr.characters.count))
- Benedict_Shiel commented on June 8th 19 at 17:36
I already even made )) I Just can't 100% verify, that is to say the input and output. I hope that in simple terms there is no difference. - sofia.Maggio commented on June 8th 19 at 17:39
thank you! With the implementation of the problem is not just. Was interested in the expressions themselves. That is to say, those parts of the text they will catch. - Benedict_Shiel commented on June 8th 19 at 17:42
June 8th 19 at 17:29
Solution
Historically, regular expressions have evolved and rewritten by different people.
There are several standards (basic regexp, extended regexp, PCRE).

Virtually all modern implementations of the basic features look the same, but the nuances rarely compares, so I'm not even sure that somewhere there is a special comparison table of all regex implementations-stand between the languages.

Just read the documentation for your implementation, immediately if something failed.

Find more questions by tags JavaScriptProgrammingRegular expressionsSwift