• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to merge regex inside java application?

 
Saloon Keeper
Posts: 6049
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my approach to handling multiple regex's: I built a helper class called "Group" that is easily processed in a loop. And to reiterate: no GUI and no formatted output at this point.

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Carey:

it works fine thanks a lot of .

I have two other questions :

1/   now I will add another regx but I want to make a loop to parse all   ( INFOP-) at once because the code display only  INFOP-0-0  and stop .

NB: INFOZ and INFOY  and INFOD their  related REGX will be added later and may be it is the same case with INFOP ( trough a loop)

I will add a new text file to explain that  ( https://www.cjoint.com/c/IHwmfnn17J5).

firstly bellow what I did:





2/  can we count the number of  EQUIPW by taken as condition only the last char ( W) .

for example in my DATA1 there is two EQUIPW  so I put the result in Jedittext or jlable ( found two )

if I change EQUIPW by EQUIPZ now the last char is changed to Z I will get ( one found EQUIPZ )

thanks


 
Carey Brown
Saloon Keeper
Posts: 6049
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • Please shorten your lines before posting them. Long lines are difficult to read on narrower screens.
  • You were missing group "ti".
  • You don't need non-capturing groups because you only care about the named groups.
  • If you want to collect all INFOP groups together make a list of all found groups and then provide logic to pick the groups you want to print to a txt file.


  •  
    Babi Astimal Astimal
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi Carey:

    lines are  just  long for explanation purpuse  but it is noted .

    1/ can you explain the use of breck in your code ?




    2/  how to make a list of all found groups and then provide logic to pick the groups you want to print to a txt file?

    thanks
     
    Babi Astimal Astimal
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi carey:

    your code work fine I didn't pay attention all INFOP are gathered at once .

    now just for design purpuse I want my result will be displayed inside JtextArea with  use of JRadioButton  in order to get bellow  information can you help us ?


    LEVELINFO=DATA=INFO-0&&NAME=EQUIP&&VERAT2=v22&&CMD4= BYTE
    LEVELINFO=DATA=INFOG-0&&MAC1=$1&&MAC2=IPARP  
    LEVELINFO=DATA=INFOT-0  
    LEVELINFO=DATA=INFOC-0&&ADRS=1&&4
    LEVELINFO=DATA=IINFOP-0-0 &&NAMEPLAT=EQUIPW&&TI 0+&&VAL1=10&&VAL2=11&&13

    thanks
     
    Carey Brown
    Saloon Keeper
    Posts: 6049
    58
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Babi Astimal Astimal wrote:can you explain the use of breck in your code ?

    The loop tries each regex in order. When you find a regex that matches then none of the remaining regexs can possibly match so there's no point in checking them. Break causes loop to abort because we already found one.
     
    Marshal
    Posts: 65108
    247
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I should have moved this discussion to our “general” forum a long time ago.
     
    Sheriff
    Posts: 6127
    157
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Babi Astimal Astimal wrote:now just for design purpuse I want my result will be displayed inside JtextArea with  use of JRadioButton  in order to get bellow  information can you help us ?


    Please ShowSomeEffort (that's a link) to do the project yourself.  Try coding it, then post any difficulties you are having.
     
    Babi Astimal Astimal
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi Knute Snortum  :

    I have followed your advices from the begining

    I have followed carey's advices also that was the answer listed bellow :


    This is my approach to handling multiple regex's: I built a helper class called "Group" that is easily processed in a loop. And to reiterate: no GUI and no formatted output at this point.



    I have posted more codes which show that i'm trying to do something.

    carey code work fine but I can't find how to keep it and add textarea and button tha's why I asked help.



     
    Knute Snortum
    Sheriff
    Posts: 6127
    157
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm assuming that JTextArea has some setText() method.  Have you tried that?

    Please TellTheDetails (that's a link) of the problem you're having.  I'm assuming you're writing a Swing program.  Have you written one before?  What resources and tutorials have you looked into?  Have you looked at this:

    https://docs.oracle.com/javase/tutorial/uiswing/index.html
     
    Babi Astimal Astimal
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi Knute Snortum:

    yes I have already started using textarea from my first message :

    textarea.append().



    Now how to put or call bellow code inside  the code listed above ?

     
    Knute Snortum
    Sheriff
    Posts: 6127
    157
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Just copy and paste it into your class, like it was a method.  I usually put them at the bottom, some people put them at the top, but anywhere will do.
     
    Babi Astimal Astimal
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have this message fault error:

    Exception in thread "main" java.lang.ExceptionInInitializerError
    Caused by: java.lang.NullPointerException
    at java.util.regex.Pattern.<init>(Unknown Source)
    at java.util.regex.Pattern.compile(Unknown Source)
    at rexdemo4$Group.<init>(rexdemo4.java:41)
    at rexdemo4.<clinit>(rexdemo4.java:28)



    sorry I have to put the whole code thanks to correct me :

     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!