wood burning stoves 2.0*
The moose likes Java in General and the fly likes Help with Java Reg expr Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help with Java Reg expr" Watch "Help with Java Reg expr" New topic
Author

Help with Java Reg expr

Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
Try this (it also allow zero to many spaces around '=':
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
Forgot to post the console output of the code I provided:

str = (if varA ="1" && varB= "2" && varC = "3")
replStr = (if varA.equals("1") && varB.equals("2") && varC.equals("3"))
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

shouldn't it be:

and
instead of


http://home.arcor.de/hirnstrom/bewerbung
Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 190
Hi all,
I need to find a way to convert an expression like this
(if varA = "1" && varB = "2" )

into Java-like sintax:

(if varA.equals("1") && varB.equals("2") )

I'd like to use Java 1.4 Api to build a Reg Expression.

I found this solution on a Unix newsgroup
sed 's/ = \("[^"]*"\)/.equals(\1)/g'

but unfortunately it doesn't work with Java String method
replaceAll(regExpr, regExpr)

Can anybody help me to find a way to do it?
How can I do it ?
Thanks a lot
Francesco


WildFly 8 Administration Book - JBoss Tutorials
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jean-Francois Briere:
Try this (it also allow zero to many spaces around '=':


Note that this doesn't work correctly for a String like "if (var=\"\\\"\")".


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stefan Wagner:
shouldn't it be:


Well, yes - but it doesn't make a difference for the regexp...
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Can you post the full java code you tried?
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
Then this:

Should produce this output:

str = if (varA ="1" && varB= "2" && varC = "3" && varD = "" && varE="Hello \"World\"" )
replStr = if (varA.equals("1") && varB.equals("2") && varC.equals("3") && varD.equals("") && varE.equals("Hello \"World\"") )
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I haven't tried, but

"\\s*=\\s*(\"(\\\\\"|[^\"])*\")"

should do it, too, shouldn't it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with Java Reg expr
 
Similar Threads
Reg. Some Thread basics
Reg Expressions
Reg. >>
useful info reg SCJP
reg a mock exam