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:
- mdc
- the specification (but that's going hard going)
- javascript kit's intro , reference
- evolt's regular expressions in javascript
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 |||/ \|/ \|| /(;)(?![";"])/
(
starts capture group in case (because(
isn't followed?
,=
, or!
change does);
literal, matches semicolon)
ends capture group(?!
starts "negative lookahead" overall expression matches if what's inside parentheses isn't found after semicolon[
begins character class, matches characters within it";"
characters within character class. (the second"
redundant.) character class contains contains;
,"
.]
ends character class)
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
Post a Comment