javascript - Learn about regular expressions? -


in answer 1 of questions, had posted:

// replace easier work delimiter str.replace(/(;)(?![";"])/g, '|')  // or split it, skip on results ; var strarr = str.split(/(;)(?![";"])/); (s in strarr) {     if (strarr[s] !== ";") {         // strarr[s]         console.log(strarr[s]);     } } 

i'm lost @ /(;)(?![";"])/. looks bunch of random symbols me :( .

where can learn more regular expression syntax?

there various resources:

regarding actual expression, / characters mark beginning , end of regular expression literal (like quotes string, although ending / may followed flags), , then:

     +------------- 1      |+------------ 2      ||+----------- 3      ||| +--------- 4      ||| |      ||| |      ||| | +------- 5      ||| | | +----- 6      ||| | | | +--- 7      ||| | | | |+-- 8      |||/ \|/ \||     /(;)(?![";"])/
  1. ( starts capture group in case (because ( isn't followed ?, =, or ! change does)
  2. ; literal, matches semicolon
  3. ) ends capture group
  4. (?! starts "negative lookahead" overall expression matches if what's inside parentheses isn't found after semicolon
  5. [ begins character class, matches characters within it
  6. ";" characters within character class. (the second " redundant.) character class contains contains ; , ".
  7. ] ends character class
  8. ) ends negative lookahead started in #4

so in all, match (and capture) semicolon provided it's not followed quote or semicolon. can't see particular reason capturing semicolon, perhaps there reason in context of question recommended.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -