Psl Psl - 4 months ago 6
Java Question

Get a particular string from a data using regular expression

I am trying to get particular string from the below data.Data is too long am here with sharing sample data.from this i have to get the

'france24Id=7GHYUFGty6fdGFHyy56'
.I have to search for
france24Id
and get its id
7GHYUFGty6fdGFHyy56

am not that much familier with RegX.Using regx how can i retrive the string 'france24Id=7GHYUFGty6fdGFHyy56' from above data.
I can get it by splitting the data using ',' but it is not an effective way.Thats y i choose regX.

2016-07-29 12:08:46,260 s=xGuide, [xre-10-pipe@6da05f7a[,connection=WebSocketConnectionWrapper[/1.8.9]]] INFO c=c.ore., - onConnect event payload={minimumVersion='0', applicationName='shell', fetl='555', authenticationToken='6y777', sessionAuthToken='', sessionGUID='null', connectURL='http://section?ruleName=Default', partnerId='hp', nativeDimensions=null, appParams={heartbeatRequest=1, france24Id=7GHYUFGty6fdGFHyy56, service=false, networkBuffer={min=150, max=150, step=0}}, deviceCaps={platform=Mac, receiverType=Native, revisions={protocol=1, auth=1, video=1}, pixelDimensions=[1280, 720]}, forceSource=null, reconnect=false, currentCommandIndex=0, reconnectReason=7, authService=9}

Answer

You can get what you want with (france\d+Id)=([a-zA-Z0-9]+),. This will grab your string and dump the two parts of it into platform-appropriate capture group variables (for instance, in Perl, $1 and $2 respectively).

In Java, your code would look a little like this:

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

public String matchID(String data) {
    Pattern r = new Pattern("(france\\d+Id)=([a-zA-Z0-9]+),");
    Matcher m = r.matcher(data);
    return m.group(2);
}
Comments