skip to main content

kiesler.at
YahooPipesRegex
Back to Page | Back to History

Difference between revisions

Version 1, 2008-06-27 13:28 Version 2, 2008-06-27 13:28
Lines 17 - 26 Lines 17 - 26
   
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)
   
# replace [\n] (line feed) with [ ] # replace [\n] (line feed) with [ ]
# replace [\r] (carriage return) with [ ] # replace [\r] (carriage return) with [ ]
# (as needed) replace all [
] (html break) with [ ]
# (as needed) replace all [
] (html break) with [ ]
# 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.
   
Lines 29 - 45 Lines 29 - 45
   
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:
   
* [.] -- one arbitrary character * [.] -- one arbitrary character
* [\d] -- one digit. (0..9) * [\d] -- one digit. (0..9)
* [\n] -- new line, like in C * [\n] -- new line, like in C
* [\r] -- carriage return, like in C * [\r] -- carriage return, like in C
* [\s] -- one space character. Includes ' ' and tabs (\t) * [\s] -- one space character. Includes ' ' and tabs (\t)
   
* [()] -- groups. You can use the groups matched in the replacement field. For example replace [(\d)] with [0$1] results in a leading zero added. * [()] -- groups. You can use the groups matched in the replacement field. For example replace [(\d)] with [0$1] results in a leading zero added.
   
* [^\d] -- combination. ^ means not, \d means digit. So one character, being everything but a digit, is matched here * [^\d] -- combination. ^ means not, \d means digit. So one character, being everything but a digit, is matched here
* [\d*] -- '*' means: 0 to n matches. This would match no or up to infinite digits. * [\d*] -- '*' means: 0 to n matches. This would match no or up to infinite digits.
* [\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\).
   
Lines 48 - 61 Lines 48 - 61
   
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]. 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 <>. * [<[^>]*>] - 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. * [<.*?>] - similar to the first statement, but "lazy match". Not as efficient.
   
   
**Showing Images** **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. 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 [ ] * Replace [(.*)] with [ ]