Link to home
Start Free TrialLog in
Avatar of k41d3n
k41d3n

asked on

Regexp?

I have a file I am reading and I need to read a value, the block of text I am reading is this:

WebRefresh=1 (0 to 10 Minute(s))
AlarmResetMode=0 (0 to 1)
BatteryChemistry=0 (0 to 1)
StringSetup=1 (1 to 2), 40 (1 to 400), 1, 17.0 ( 6.5, 7.0, 8.0, 9.0,12.0,13.5,17.0)
BatteryAHCapacity=100 (100 to 2000)
BalanceBoostTime=3 (3 to 10 Second(s))
CellVoltageLimitMinMax=2.150, 2.400 (2.000 to 2.500 V)
PilotTempLimitMax=95.0 F (85.0 to 120.0 F)
AmbientTempLimitMinMax=50.0, 95.0 F (50.0 to 120.0 F)
ResponseDeviationAlarmLevel=20 (10 to 20 %)
DischargeDeviationAlarmLevel=15 (5 to 20 %)
RippleCurrentAlarmLevel=5 (0 to 2000)

now, what I do now, is look for the parameter then split it on the = sign and I need to return everything after the = sign up to the ( how would I go about this?

I am horrible with expressions.

This is what I have now that splits the = sign.

                String setLine;
                String changeValue;
                while (in.available() != 0) {
                    // Print file line to screen
                    System.out.println(""+in.readLine()+ "\n");
                    setLine = in.readLine();
                    if (setLine.indexOf("DischargeDeviationAlarmLevel") != -1) {
                        String[] line = setLine.split("=");
                        changeValue = line[1].substring(1, 2);
                        System.out.println(changeValue);
                        break;
                    }
                }

Of course code syntax suggestions always welcome as well.
Avatar of k41d3n
k41d3n

ASKER

And the line

 changeValue = line[1].substring(1, 2);

is actually

 changeValue = line[1];
Avatar of CEHJ
You can use this to read that file:

Properties props = new Properties();
props.load(new FileInputStream(yourFile));
String value = props.getProperty("ResponseDeviationAlarmLevel"); // gets "20 (10 to 20 %)"
Avatar of k41d3n

ASKER

I ended up using:

                String setLine;
                String changeValue;
                while (in.available() != 0) {
                    // Print file line to screen
                    System.out.println(""+in.readLine()+ "\n");
                    setLine = in.readLine();
                    if (setLine.indexOf("DischargeDeviationAlarmLevel") != -1) {
                        String[] line = setLine.split("=");
                        changeValue = line[1].substring(0, line[1].indexOf("("));
                        System.out.println(changeValue);
                        break;
                    }
                }
hi
one example to extract the e-mail addres from a string like "dfd gfdg dgdgd hje@juf.com ejfek" using RegExp
<html>
<head>
<script>
function findEmail(str) {
    var regex=/[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]/;
    var m=str.match(regex);
    alert(m);
}
</script>
</head>
<body>

<button onclick="javascript:findEmail('the email address Myemail@hotmail.com could be anywhere');">Find the Email</button>

</body>
</html>

or

inputs.match(/(\w+)[@](\w+)[.](\w+)/g,"");


u can try the same logic for ur case
try something like:

                String setLine = null;
                String changeValue = null;
                while (null!=(setLine=in.readLine())) {
                    // Print file line to screen
                    System.out.println(""+setLine+ "\n");
                     if (setLine.indexOf("DischargeDeviationAlarmLevel") != -1) {
                        changeValue = setLine.split("=")[1].split(" ")[0];
//                        or perhaps depending on possible format of value
//                        changeValue = setLine.split("=")[1].split("\\(")[0];
                        System.out.println(changeValue);
                    }
                }
ASKER CERTIFIED SOLUTION
Avatar of Ortokobold
Ortokobold

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial