## cascading.operation.regex
Class RegexParser

    java.lang.Object
      cascading.operation.BaseOperation<C>
          cascading.operation.regex.RegexOperation<Pair<Matcher,Tuple>>
              cascading.operation.regex.RegexParser

All Implemented Interfaces:
  DeclaresResults, Function<Pair<Matcher,Tuple>>, Operation<Pair<Matcher,Tuple>>, Traceable, Serializable

    public class RegexParser

extends RegexOperation<Pair<Matcher,Tuple>>
implements Function<Pair<Matcher,Tuple>>

Class RegexParser is used to extract a matched regex from an incoming argument value.

Sometimes its useful to parse out a value from a key/value pair in a string, if the key exists. If the key does not exist, returning an empty string instead of failing is typically expected.

The following regex can extract a value from `key1=value1&key2=value2` if key1 exists, otherwise an empty string is returned:

    (?<=key1=)[^&]*|$

See Also:
  Serialized Form

Field Summary

Fields inherited from class cascading.operation.regex.RegexOperation
`patternString`

Fields inherited from class cascading.operation.BaseOperation
`fieldDeclaration, numArgs, trace`

Fields inherited from interface cascading.operation.Operation
`ANY`

Constructor Summary
`RegexParser(Fields fieldDeclaration, String patternString)` Constructor RegexParser creates a new RegexParser instance, where the argument Tuple value is matched and returned as the given Field.
`RegexParser(Fields fieldDeclaration, String patternString, int[] groups)` Constructor RegexParser creates a new RegexParser instance, where the patternString is a regular expression with match groups and whose groups designated by `groups` are stored in the named fieldDeclarations.
`RegexParser(String patternString)` Constructor RegexParser creates a new RegexParser instance, where the argument Tuple value is matched and returned in a new Tuple.
`RegexParser(String patternString, int[] groups)` Constructor RegexParser creates a new RegexParser instance, where the patternString is a regular expression with match groups and whose groups designated by `groups` are stored in the appropriate number of new fields.

Method Summary
`boolean` `equals(Object object)`
`int[]` `getGroups()`
`int` `hashCode()`
`void` `operate(FlowProcess flowProcess, FunctionCall<Pair<Matcher,Tuple>> functionCall)` Method operate provides the implementation of this Function.
`void` `prepare(FlowProcess flowProcess, OperationCall<Pair<Matcher,Tuple>> operationCall)` Method prepare does nothing, and may safely be overridden.

Methods inherited from class cascading.operation.regex.RegexOperation
`getPattern, getPatternString`

Methods inherited from class cascading.operation.BaseOperation
`cleanup, flush, getFieldDeclaration, getNumArgs, getTrace, isSafe, printOperationInternal, toString, toStringInternal`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface cascading.operation.Operation
`cleanup, flush, getFieldDeclaration, getNumArgs, isSafe`

Constructor Detail

### RegexParser

    @ConstructorProperties(value="patternString")
    public RegexParser(String patternString)

  Constructor RegexParser creates a new RegexParser instance, where the argument Tuple value is matched and returned in a new Tuple.

  If the given patternString declares regular expression groups, each group will be returned as a value in the resulting Tuple. If no groups are declared, the match will be returned as the only value in the resulting Tuple.

  The fields returned will be `Fields.UNKNOWN`, so a variable number of values may be emitted based on the regular expression given.

  Parameters:
    `patternString` - of type String

### RegexParser

    @ConstructorProperties(value={"fieldDeclaration","patternString"})
    public RegexParser(Fields fieldDeclaration,
                                                  String patternString)

  Constructor RegexParser creates a new RegexParser instance, where the argument Tuple value is matched and returned as the given Field.

  If the given patternString declares regular expression groups, each group will be returned as a value in the resulting Tuple. If no groups are declared, the match will be returned as the only value in the resulting Tuple.

  If the number of fields in the fieldDeclaration does not match the number of groups matched, an `OperationException` will be thrown during runtime.

  To overcome this, either use the constructors that take an array of groups, or use the `(?: ...)` sequence to tell the regular expression matcher to not capture the group.

  Parameters:
    `fieldDeclaration` - of type Fields
    `patternString` - of type String

### RegexParser

    @ConstructorProperties(value={"patternString","groups"})
    public RegexParser(String patternString,
                                                  int[] groups)

  Constructor RegexParser creates a new RegexParser instance, where the patternString is a regular expression with match groups and whose groups designated by `groups` are stored in the appropriate number of new fields.

  The number of resulting fields will match the number of groups given (`groups.length`).

  Parameters:
    `patternString` - of type String
    `groups` - of type int[]

### RegexParser

    @ConstructorProperties(value={"fieldDeclaration","patternString","groups"})
    public RegexParser(Fields fieldDeclaration,
                                                  String patternString,
                                                  int[] groups)

  Constructor RegexParser creates a new RegexParser instance, where the patternString is a regular expression with match groups and whose groups designated by `groups` are stored in the named fieldDeclarations.

  Parameters:
    `fieldDeclaration` - of type Fields
    `patternString` - of type String
    `groups` - of type int[]

Method Detail

### getGroups

    public int[] getGroups()

### prepare

    public void prepare(FlowProcess flowProcess,
                        OperationCall<Pair<Matcher,Tuple>> operationCall)

  Description copied from class: `BaseOperation`
  Method prepare does nothing, and may safely be overridden.

  Specified by:
    `prepare` in interface `Operation<Pair<Matcher,Tuple>>`
  Overrides:
    `prepare` in class `BaseOperation<Pair<Matcher,Tuple>>`

### operate

    public void operate(FlowProcess flowProcess,
                        FunctionCall<Pair<Matcher,Tuple>> functionCall)

  Description copied from interface: `Function`
  Method operate provides the implementation of this Function.

  Specified by:
    `operate` in interface `Function<Pair<Matcher,Tuple>>`
  Parameters:
    `flowProcess` - of type FlowProcess
    `functionCall` - of type FunctionCall

### equals

    public boolean equals(Object object)

  Overrides:
    `equals` in class `RegexOperation<Pair<Matcher,Tuple>>`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `RegexOperation<Pair<Matcher,Tuple>>`

Copyright © 2007-2014 Concurrent, Inc. All Rights Reserved.