I am a fan of JavaScript. I saw this other (now deleted) question , and it made me think. Can you tell me what the exact expression below means?
split(/\|(?=\w=>)/)
Does it split the string with |?
|
The regular expression is in the braid. It means
\| # A pipe symbol. It needs to be scaped with a backslash # because otherwise it means "OR" (?= # a so-called lookahead group. It checks if its contents match # at the current position without actually advancing in the string \w=> # a word character (a-z, A-Z, 0-9, _) followed by => ) # end of lookahead group.
It breaks the string into |, but only if it follows char in [a-zA-Z0-9_]and=>
[a-zA-Z0-9_]
=>
Example:
He will divide a|b=>into|
a|b=>
It will not break a|binto|
a|b
'|' (?) - (\ w, [a-zA-Z0-9_]) + '= > '.
, javascript
:
/
\|
\
(?=
\w=>
_
)/
, |, - , =>.
, . , - "= > ".
"|" OR. :
split(/k|i|tt|y/)
"k", "i", "tt", "y".
, \|(?=\w=>)
\|(?=\w=>)
(?=REGEX)
REGEX
\|\w=>
|a=>
, /\|(?=\w=>)/ |, \w=>. |a=>, |a>, || ..
/\|(?=\w=>)/
|a>
||
: a=>aa|b=>b||b|c=>cc. lookahead, split [a=>aa, b||b, cc]. [a=>aa, b=>b||b, c=>cc], .
a=>aa|b=>b||b|c=>cc
[a=>aa, b||b, cc]
[a=>aa, b=>b||b, c=>cc]