Advertisement
snake5

regex alternative draft 0.1

Feb 20th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <img src='blah' alt='foo' />
  2.  
  3. // extracting content of 'src' from one html image element
  4. string '<img' not string '/>' string 'src=' extract quoted '\'','"' '\\' not string '<img' string '/>'
  5.  
  6. - string '<img' - string to look for
  7. - not string '/>' - discard if this string was found before...
  8. - string 'src=' - string to look for
  9. - extract - add to output array
  10. - quoted '\'','"' '\\' - match a quote (arg1 - quoting strings, arg2 - escaping string)
  11. - not string 'img' - discard if this string was found before...
  12. - string '/>' - string to look for
  13.  
  14. grammar
  15.  
  16. string-literal-list: <string-literal> [ ',' <string-literal> ] x 0+
  17. string-check: 'string' <string-literal> // get position of string, fail if not found
  18. not-check: 'not' <function> <function> // get position of both functions, fail if 1 before 2
  19. quoted-check: 'quoted' <string-literal-list> <string-literal-list> // get position of quoted string, fail if not found
  20. extract-op: 'extract' <function> // mark range for extraction
  21. match: <string-check> | <not-check> | <quoted-check> | <extract-op>
  22. match-list <match> [ <match> ] x 0+
  23. program: <match-list>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement