What does regular expression mean \ | (? = \ W =>)?

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 |?

+5
source share
6 answers

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.
+7
source

It breaks the string into |, but only if it follows char in [a-zA-Z0-9_]and=>

Example:

He will divide a|b=>into|

It will not break a|binto|

+4
source

'|' (?) - (\ w, [a-zA-Z0-9_]) + '= > '.

, javascript

+2

:

  • /
  • \| | , | , \
  • (?= lookahead, , , .
  • \w=> - ( _), =>
  • )/ lookahead

, |, - , =>.

+1

, . , - "= > ".

"|" OR. :

split(/k|i|tt|y/)

"k", "i", "tt", "y".

0

, \|(?=\w=>)

  • | , \|
  • (?=REGEX) : REGEX , , REGEX. REGEX . \|\w=>, |a=> |.

, /\|(?=\w=>)/ |, \w=>. |a=>, |a>, || ..

: a=>aa|b=>b||b|c=>cc. lookahead, split [a=>aa, b||b, cc]. [a=>aa, b=>b||b, c=>cc], .

0

All Articles