Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22863

regexp(ing) Backus-Naurish expressions ...

From qwertmonkey@syberianoutpost.ru
Newsgroups comp.lang.java.programmer
Subject regexp(ing) Backus-Naurish expressions ...
Date 2013-03-10 02:27 +0000
Organization Aioe.org NNTP Server
Message-ID <khgr2k$u3b$1@speranza.aioe.org> (permalink)

Show all headers | View raw


 I need to set up some code's running context via properties files and I want
to make sure that users don't get too playful messing with them, because that
could alter results greatly and in unexpected ways (they must probably won't
be able to make sense of and then they would bother the hell out of you)
~ 
 So, I must do some sanity check the running parameters if entered via the 
command prompt or if the defaults are used from the properties files
~ 
 I am telling you all of that because you many know of libraries to do such
thing
~ 
 I think one possible way to do that is via a regexp, which should match all
the options included in the test array aISAr
~ 
 One of the problems I am having is that if you enter as options say [true|t],
the matcher would match just the "t" of "true" and I want for "true" to be
actually matched another one is that, say, " true ", should be matched, as well
as "false [ nix |mac| windows ] line.separator" ...
~ 
 Any ideas you would share?
~ 
 thanks,
 lbrtchx
~ 
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TEST CODE ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 

import java.util.regex.Matcher;
import java.util.regex.Pattern;

// __ 
public class RegexMatches02Test{
// __ 
 public static void main( String args[] ){
  String aRegEx;
  String aIS;
  Pattern Ptrn;
  Matcher Mtchr;
  int iCnt, iMtxStart, iMtxEnd;
// __ 
  aRegEx = "^\\s*[true|false|t|f]{1}\\s*\\[";
  aRegEx = "^\\s*[true|false|t|f]{1}";
  aRegEx = "^\\s*[true|false|t|f]{1}\\s*";
  aRegEx = "^\\s*[true|false t|f]{1}\\s*";

// __ 
  String[] aISAr = new String[]{
     " true[a|b |c ] q"
   , " true [a|b |c ] q"
   , "true [a|b |c ] q"
   , "true[a|b|c] b"
   , "true[a|b|c]q"
   , "False[ y | n | q ] q"
   , "false[nix|windows|mac]line.separator"
   , "false [ nix |mac| windows ] line.separator"
   , "T[y|n]q"
   , "T[y]"
   , "false"
   , "faLse"
   , "true"
   , "TrUe"
   , "F"
   , "T"
  };
  int iISArL = aISAr.length, i = 0;
// __ 
  boolean IsLoop;
  Ptrn = Pattern.compile(aRegEx, Pattern.CASE_INSENSITIVE);

  System.err.println("// __ matching pattern: |" + aRegEx + "|");

  Mtchr = Ptrn.matcher(aISAr[i]); // get a matcher object
  IsLoop = (i < iISArL);
  while(IsLoop){
   System.err.println("// __ |" + i + "|" + aISAr[i] + "|");
   iCnt = 0;
// __ 
   while(Mtchr.find()){
    iMtxStart = Mtchr.start();
    iMtxEnd = Mtchr.end();
    System.err.println("|" + iCnt + "|" + iMtxStart + "|" + iMtxEnd + "|" +
 aISAr[i].substring(iMtxStart, iMtxEnd) + "|");
    ++iCnt;
   }// (Mtchr.find())
   System.err.println("~");
// __ 
   ++i;
   IsLoop = (i < iISArL);
   if(IsLoop){ Mtchr.reset(aISAr[i]); }
  }// while(IsLoop)
 }
}

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

regexp(ing) Backus-Naurish expressions ... qwertmonkey@syberianoutpost.ru - 2013-03-10 02:27 +0000
  Re: regexp(ing) Backus-Naurish expressions ... Arne Vajhøj <arne@vajhoej.dk> - 2013-03-09 21:33 -0500
  Re: regexp(ing) Backus-Naurish expressions ... Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-03-09 21:00 -0600
  Re: regexp(ing) Backus-Naurish expressions ... Leif Roar Moldskred <leifm@dimnakorr.com> - 2013-03-09 23:33 -0600
  Re: regexp(ing) Backus-Naurish expressions ... lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-10 10:27 +0000
  Re: regexp(ing) Backus-Naurish expressions ... Martin Gregorie <martin@address-in-sig.invalid> - 2013-03-10 12:55 +0000
  Re: regexp(ing) Backus-Naurish expressions ... Roedy Green <see_website@mindprod.com.invalid> - 2013-03-10 07:57 -0700
    Re: regexp(ing) Backus-Naurish expressions ... Robert Klemme <shortcutter@googlemail.com> - 2013-03-10 22:39 +0100
      Re: regexp(ing) Backus-Naurish expressions ... Roedy Green <see_website@mindprod.com.invalid> - 2013-03-10 15:54 -0700
        Re: regexp(ing) Backus-Naurish expressions ... Robert Klemme <shortcutter@googlemail.com> - 2013-03-11 21:03 +0100
        Re: regexp(ing) Backus-Naurish expressions ... Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-03-11 17:00 -0500
          Re: regexp(ing) Backus-Naurish expressions ... Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-11 18:31 -0400
            Re: regexp(ing) Backus-Naurish expressions ... Arne Vajhøj <arne@vajhoej.dk> - 2013-03-11 18:40 -0400
              Re: regexp(ing) Backus-Naurish expressions ... Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-11 21:39 -0400
          Re: regexp(ing) Backus-Naurish expressions ... Martin Gregorie <martin@address-in-sig.invalid> - 2013-03-11 23:06 +0000
          Re: regexp(ing) Backus-Naurish expressions ... Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-03-11 20:56 -0500
            Re: regexp(ing) Backus-Naurish expressions ... Arne Vajhøj <arne@vajhoej.dk> - 2013-03-11 22:06 -0400
            Re: regexp(ing) Backus-Naurish expressions ... Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-12 09:30 -0400
      Re: regexp(ing) Backus-Naurish expressions ... Roedy Green <see_website@mindprod.com.invalid> - 2013-03-10 16:24 -0700
        Re: regexp(ing) Backus-Naurish expressions ... Robert Klemme <shortcutter@googlemail.com> - 2013-03-11 21:08 +0100
          Re: regexp(ing) Backus-Naurish expressions ... Arne Vajhøj <arne@vajhoej.dk> - 2013-03-11 16:59 -0400
            Re: regexp(ing) Backus-Naurish expressions ... Robert Klemme <shortcutter@googlemail.com> - 2013-03-11 22:24 +0100
      Re: regexp(ing) Backus-Naurish expressions ... Robert Klemme <shortcutter@googlemail.com> - 2013-03-11 21:00 +0100
    Re: regexp(ing) Backus-Naurish expressions ... Robert Klemme <shortcutter@googlemail.com> - 2013-03-13 08:07 +0100
  Re: regexp(ing) Backus-Naurish expressions ... markspace <markspace@nospam.nospam> - 2013-03-10 11:16 -0700

csiph-web