[ 
https://issues.apache.org/jira/browse/METRON-933?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16082607#comment-16082607
 ] 

ASF GitHub Bot commented on METRON-933:
---------------------------------------

Github user JonZeolla commented on a diff in the pull request:

    https://github.com/apache/metron/pull/638#discussion_r126739325
  
    --- Diff: 
metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RegExFunctions.java
 ---
    @@ -0,0 +1,103 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.metron.stellar.dsl.functions;
    +
    +import java.util.List;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +import org.apache.metron.stellar.common.utils.ConversionUtils;
    +import org.apache.metron.stellar.common.utils.PatternCache;
    +import org.apache.metron.stellar.dsl.BaseStellarFunction;
    +import org.apache.metron.stellar.dsl.Stellar;
    +
    +public class RegExFunctions {
    +
    +  @Stellar(name = "REGEXP_MATCH",
    +      description = "Determines whether a regex matches a string",
    +      params = {
    +          "string - The string to test",
    +          "pattern - The proposed regex pattern"
    +      },
    +      returns = "True if the regex pattern matches the string and false if 
otherwise.")
    +  public static class RegexpMatch extends BaseStellarFunction {
    +
    +    @Override
    +    public Object apply(List<Object> list) {
    +      if (list.size() < 2) {
    +        throw new IllegalStateException(
    +            "REGEXP_MATCH expects two args: [string, pattern] where 
pattern is a regexp pattern");
    +      }
    +      String patternString = (String) list.get(1);
    +      String str = (String) list.get(0);
    +      if (str == null || patternString == null) {
    +        return false;
    +      }
    +      return 
PatternCache.INSTANCE.getPattern(patternString).matcher(str).matches();
    +    }
    +  }
    +
    +  @Stellar(name = "REGEXP_GROUP_VAL",
    +      description = "Returns the value of a group in a regex against a 
string",
    +      params = {
    +          "string - The string to test",
    +          "pattern - The proposed regex pattern",
    +          "group - integer that selects what group to select, starting at 
1"
    +      },
    +      returns = "The value of the group, or null if not matched or no 
group at index")
    +  public static class RegexpGroupValue extends BaseStellarFunction {
    +
    +    @Override
    +    public Object apply(List<Object> list) {
    +      if (list.size() < 3) {
    --- End diff --
    
    Why isn't this `!=`, since any arguments after the 3rd are ignored?


> STELLAR support for setting fields to regex match captures
> ----------------------------------------------------------
>
>                 Key: METRON-933
>                 URL: https://issues.apache.org/jira/browse/METRON-933
>             Project: Metron
>          Issue Type: New Feature
>            Reporter: Otto Fowler
>            Assignee: Otto Fowler
>
> The capability to do a regex on a field, and set one or more fields to the 
> resulting captures would be useful.
> https://docs.oracle.com/javase/tutorial/essential/regex/groups.html



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to