Class VerbalExpression

java.lang.Object
ru.lanwen.verbalregex.VerbalExpression

public class VerbalExpression extends Object
  • Field Details

    • pattern

      private final Pattern pattern
  • Constructor Details

  • Method Details

    • testExact

      public boolean testExact(String pToTest)
      Test that full string matches regular expression
      Parameters:
      pToTest - - string to check match
      Returns:
      true if matches exact string, false otherwise
    • test

      public boolean test(String pToTest)
      Test that full string contains regex
      Parameters:
      pToTest - - string to check match
      Returns:
      true if string contains regex, false otherwise
    • getText

      public String getText(String toTest)
      Extract full string that matches regex Same as getText(String, int) for 0 group
      Parameters:
      toTest - - string to extract from
      Returns:
      group 0, extracted from text
    • getText

      public String getText(String toTest, int group)
      Extract exact group from string
      Parameters:
      toTest - - string to extract from
      group - - group to extract
      Returns:
      extracted group
      Since:
      1.1
    • getText

      public String getText(String toTest, String group)
      Extract exact named-group from string

      Example is see to VerbalExpression.Builder.capture(String)

      Parameters:
      toTest - - string to extract from
      group - - group to extract
      Returns:
      extracted group
      Since:
      1.6
    • getTextGroups

      public List<String> getTextGroups(String toTest, int group)
      Extract exact group from string and add it to list Example: String text = "SampleHelloWorldString"; VerbalExpression regex = regex().capt().oneOf("Hello", "World").endCapt().maybe("String").build(); list = regex.getTextGroups(text, 0) //result: "Hello", "WorldString" list = regex.getTextGroups(text, 1) //result: "Hello", "World"
      Parameters:
      toTest - - string to extract from
      group - - group to extract
      Returns:
      list of extracted groups
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • regex

      public static VerbalExpression.Builder regex(VerbalExpression.Builder pBuilder)
      Creates new instance of VerbalExpression builder from cloned builder
      Parameters:
      pBuilder - - instance to clone
      Returns:
      new VerbalExpression.Builder copied from passed
      Since:
      1.1
    • regex

      public static VerbalExpression.Builder regex()
      Creates new instance of VerbalExpression builder
      Returns:
      new VerbalExpression.Builder
      Since:
      1.1