skip to main content

kiesler.at
YahooPipesRegex
Back to Page | Back to History

Difference between revisions

Version 0, 2008-06-27 11:19 Version 1, 2008-06-27 11:28
Lines 8 - 31 Lines 8 - 31
   
The RegEx module is one of the most powerful modules in Yahoo Pipes. You can do all kind of data transformations with it. This wiki page here would like to give you a short overview. The RegEx module is one of the most powerful modules in Yahoo Pipes. You can do all kind of data transformations with it. This wiki page here would like to give you a short overview.
   
*Please note*: Like in the Yahoo Pipes discussions, I put RegEx patterns within square brackets. That way, you can distinguish for example [] and [ ] easily. Please omit the square brackets unless noted otherwise. **Please note**: Like in the Yahoo Pipes discussions, I put RegEx patterns within square brackets. That way, you can distinguish for example [] and [ ] easily. Please omit the square brackets unless noted otherwise.
   
   
+++ Common patterns +++ Common patterns
   
*Removing whitespace* **Removing whitespace**
   
Sometimes, you'd like to remove all the linefeeds and unwanted spaces out of a field. I usually use a three- to fourfold approach to that. For each of the following replacements, use +g (the global flag) Sometimes, you'd like to remove all the linefeeds and unwanted spaces out of a field. I usually use a three- to fourfold approach to that. For each of the following replacements, use +g (the global flag)
   
1) replace [\n] (line feed) with [ ] # replace [\n] (line feed) with [ ]
2) replace [\r] (carriage return) with [ ] # replace [\r] (carriage return) with [ ]
3) (as needed) replace all [
] (html break) with [ ]
# (as needed) replace all [
] (html break) with [ ]
4) replace [\s+] (all whitespace occurrences) with [ ] # replace [\s+] (all whitespace occurrences) with [ ]
   
With 1 and 2, you remove all hard linefeeds. With 3, you remove all "logical" linefeeds (the ones that only get rendered, when the field is interpreted as html). with 4, you make the result more compact. If for example you have 3 or more spaces in a row, those will be reduced to just one space. With 1 and 2, you remove all hard linefeeds. With 3, you remove all "logical" linefeeds (the ones that only get rendered, when the field is interpreted as html). with 4, you make the result more compact. If for example you have 3 or more spaces in a row, those will be reduced to just one space.
   
   
*Using reserved characters* **Using reserved characters**
   
In RegEx, some characters are "reserved". That means, they are not used literally, but instead used as functions. Examples: In RegEx, some characters are "reserved". That means, they are not used literally, but instead used as functions. Examples:
   
Lines 42 - 45 Lines 42 - 61
* [\d+] -- '+' means: 1 to n matches. At least one. This would match one or more digits. * [\d+] -- '+' means: 1 to n matches. At least one. This would match one or more digits.
   
To "escape" reserved characters, that is to match them literally, you put a backslash in front. For example, matching [http://discuss.pipes.yahoo.com/Message_Boards_for_Pipes/threadview?m=te&bn=pip-DeveloperHelp&tid=4832&mid=4832&tof=3&frt=2#4832 (twitter)] is possible by using \(twitter\). To "escape" reserved characters, that is to match them literally, you put a backslash in front. For example, matching [http://discuss.pipes.yahoo.com/Message_Boards_for_Pipes/threadview?m=te&bn=pip-DeveloperHelp&tid=4832&mid=4832&tof=3&frt=2#4832 (twitter)] is possible by using \(twitter\).
   
   
  **Removing html tags**
   
  From a post in the [http://discuss.pipes.yahoo.com/Message_Boards_for_Pipes/threadview?m=te&bn=pip-DeveloperHelp&tid=4813&mid=4813&tof=5&frt=2#4813 Yahoo Pipes Discussion].
   
  * [<[^>]*>] - please note that this translates to something like <[^>]*> . matches every term that's within <>.
  * [<.*?>] - similar to the first statement, but "lazy match". Not as efficient.
   
   
  **Showing Images**
   
  From a post in the [http://discuss.pipes.yahoo.com/Message_Boards_for_Pipes/threadview?m=te&bn=pip-DeveloperHelp&tid=4654&mid=4654&tof=26&frt=2#4654 Yahoo Pipes Discussion]. Sometimes, one of your field contains just an image URL. You'd like to replace that URL with an image tag, so it is rendered as an image.
   
  * Replace [(.*)] with [ ]