code_junkie

How to cycle through delimited tokens with a Regular Expression?

Nov 10th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. text ###token1### text text ###token2### text text
  2.  
  3. $text = 'text ###token1### text text ###token2### text text';
  4.  
  5. while($text =~ m/###(.+?)###/g) {
  6. print $1, "n";
  7. }
  8.  
  9. @tokens = $text =~ m/###(.+?)###/g;
  10.  
  11. /###.+###/
  12.  
  13. text (#+.+#+) text text (#+.+#+) text text
  14.  
  15. token1: 1, token2: 2
  16.  
  17. token1: ###token1###, token2: ###token2###
Add Comment
Please, Sign In to add comment