[
https://issues.apache.org/jira/browse/PIG-2905?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Cheolsoo Park updated PIG-2905:
-------------------------------
Attachment: PIG-2905.patch
I added the following text to the REPLACE doc:
{quote}
Note that the REPLACE function is internally implemented using
[java.string.replaceAll(String regex, String
replacement)|http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#replaceAll(java.lang.String,
java.lang.String)] where 'regExp' and 'newChar' are passed as the 1st and 2nd
argument respectively. If you want to replace [special
characters|http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#bs]
such as '[' in the string literal, it is necessary to escape them in 'regExp'
by prefixing them with double backslashes.
{quote}
Thanks!
> Improve documentation around REPLACE
> ------------------------------------
>
> Key: PIG-2905
> URL: https://issues.apache.org/jira/browse/PIG-2905
> Project: Pig
> Issue Type: Sub-task
> Components: documentation
> Reporter: Bill Graham
> Assignee: Cheolsoo Park
> Attachments: PIG-2905.patch
>
>
> Document how REPLACE uses a Java regex and link out to JDK docs describing
> reserved characters and escaping. From recent confusion on the users list:
> {noformat}
> > String source = "[02/Aug/2012:05:01:17";
> > > String target ="[";
> > > String replaceWith = "";
> > > return source.replaceAll(source, target, replaceWith);
> > Note that Java String.replaceAll() takes a regular expression for the 2nd
> > parameter (i.e. target), and "[" is a special character. To use it as is,
> > you have to escape it, so in your Pig script, you should do:
> > REPLACE(date,'\\[','')
> {noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira