Creating regular expression to get desired info

Hi all!!!
I have a little problem. I need to get the line below, but i NEED to use regular expression. I am useing java.text.regex correctly, but I dont really know how to create a regex pattern. my line is :
[2004/01/06 12:43:58.735] [info] br.com.organox.web.aggregator.servlet.struts.action.LoginEmbeddedAction: User 'TESTER12345678' with ticket 'acLBF9a6ZiY41073400238626' logged in.
and i need to get these two values
'TESTER12345678' and 'logged in'
can anyone help me?

You could try this:
String line = "[2004/01/06 12:43:58.735] [info] br.com.organox.web.aggregator.servlet.struts.action.LoginEmbeddedAction: User 'TESTER12345678' with ticket 'acLBF9a6ZiY41073400238626' logged in.";
String pattern = "User '(.+?)'.+' (.+)";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(line);
String user = null;
String status = null;
if (m.find())
    user = m.group(1);
    status= m.group(2);
System.out.println("user=" + user + ", status=" + status);By the way, next time post at the "Jave programming" forum instead.

Similar Messages

  • How to write regular expression to find desired string piece *duplicate*

    Hi All,
    Suppose that i have following string piece:
    name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
    ali
    mehmetI use following statement
    SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
      2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
      3  );
    LST                                                NM
    name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
    SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
    Any ideas about regexp?
    Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
    Regards...
    Mennan
    Edited by: mennan on Jul 4, 2010 9:53 PM
    thread was posted twice due to chrome refresfment. Please ignore the thread and reply to How to write regular expression to find desired string piece

    The approach is to do cartesian join to a 'number' table returning number of records equal to number of names in the string.I have hardcoded 2 but you can use regexp_count to get the number of occurrences of the pattern in the string and then use level <=regexp_count(..... .
    See below for the approach
    with cte as(
    select
    'name:ali#lastname:kemal#name:mehmet#lastname:cemal' col ,level lev
    from dual connect by level <=2)
    select substr(regexp_substr('#'||col,'#name:\w+',1,lev),7)
    from cte
    /

  • Using regular expressions to get a customized output

    Hi,
    I have a string/varchar variable with the data ',a,b,c,' in it.
    I want the display as follows:
    a
    b
    c
    I would like to get the similar output using regular expressions.
    How do I get this output using REGEXP_REPLACE or REGEXP_SUBSTR?
    Please do the needful.
    Thanks & Regards,
    Rakshit

    I remember that, however if we look closer, that one has a little flaw: The 2nd row should be null, because ",," indicates an empy field. The MODEL clause solution works just fine in this case:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)
    -- end of sample data
    SELECT col_new
      FROM t
    MODEL
       PARTITION BY (ROWNUM rn)
       DIMENSION BY (0 dim)
       MEASURES(col1, col1 col_new)
       RULES ITERATE(99) UNTIL (ITERATION_NUMBER = LENGTH(REGEXP_REPLACE(col1[0], '[^,]')))
                    (col_new[ITERATION_NUMBER] = REPLACE(REGEXP_SUBSTR(col1[0], '(^|,)[^,]*', 1, ITERATION_NUMBER+1), ','))
    COL_NEW                                                                                                                                                                  
    aaaa                                                                                                                                                                     
    bbbb                                                                                                                                                                     
    cccc                                                                                                                                                                     
    dddd                                                                                                                                                                     
    eeee
    ffff
    7 Zeilen ausgewählt.Update: I had this nagging feeling that I missed something, and there it was. If you want to see what the problem with my solution is, change the example to
    with t as (select ',aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)So I went back and tried to fix BlueShadows approach. Here it is:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' txt from dual)
    -- end of sample data
    SELECT REPLACE(REGEXP_SUBSTR(',' || txt, ',[^,]*', 1, level), ',') col_new
      FROM t
      CONNECT BY level <= length(regexp_replace(txt,'[^,]*'))+1
    ;C.

  • Is there a way to be sure that created Regular expression (Class RegExp) is valid?

    Is it possible to create wrong Regular expression in  ActionScript/Flex which will cause runtime error? Or how to validate RegExp?
    I've tried so many  weird regexpes in Flash and Flex, it never complained! How do I know If my  regexp valid?

    "It is VERY reliable. If match() returns null - this means that String doesn't have any parts that match pattern."
    Exactly, but is doenst mean that syntax of RegExp is correct since you dont know what gave you null
    Apparemtly /foo([/ is wrong expression, and Java compiller complains:
    Unclosed character class near index 4 foo([     ^
    but in AS3 i can create
    var xxd:RegExp = /foo([/;
    when I do xxd.exec("") it got null;
    and no complains!! How to understand that?
    But in same time
    var xxd:RegExp = /foo/;
    xxd.exec(""), will be null as well!?

  • Question about creating regular expression

    Hi!
    I am creating parser for the specific configuration file. Now I have got small problem: I need to find the line with text in format "key value".
    For example I have this text file:
    entry {
         key value
         key2 value2
         entry2 {
         }I wish to find, using java.regex, these two lines: "key value" and "key2 value2". But how?

    Is your problem that you don't understand regular expressions? If so then this might help. Or is your problem you don't understand Java regular expressions? If so then this might help. Or is your problem that you don't understand how to read lines of a file? If so then this might help.

  • How to write regular expression to find desired string piece

    Hi All,
    Suppose that i have following string piece:
    name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
    ali
    mehmetI use following statement
    SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
      2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
      3  );
    LST                                                NM
    name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
    SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
    Any ideas about regexp?
    Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
    Regards...
    Mennan

    Hi, Mennan,
    You can nest REGEXP_SUBSTR withing REGEXP_REPLACE to get the n-th occurrence, like this:
    SELECT     lst
    ,      REGEXP_REPLACE ( REGEXP_SUBSTR ( lst
                                      , 'name:[^#]*#lastname'
                               , 1
                               , n
                     , 'name:(.*)#lastname'
                     , '\1'
                     )      AS nm If the pattern occurs fewer than n times, the expression above returns NULL.

  • Regular expression to get substring from string

    Hi,
    I’m having the following problem:
    SELECT REGEXP_SUBSTR(';first field;ir-second field-02;ir-second field-01; third field','.*ir-(.*)-01.*’)FROM dual
    [\CODE]
    This is the select that I have with a java expression!
    In java I’m able to do find the right expression to retrieve what I want, but I don’t know how to adapt this for oracle!
      In oracle I was trying to do something like this:
    NVL(SUBSTR(REGEXP_SUBSTR(CONCAT(';', list),';ir-[^01;]+'),LENGTH(';ir-')+1,LENGTH(REGEXP_SUBSTR(CONCAT(';',list),';ir-[^01;]+'))), ' ') AS result
    [\CODE]
    But it doesn’t work because “ir” can repeat in other parameters.
    “ir-something-01” only appears once.
    Is it in oracle a logic similar to result groups in oracle?
    best regards,
    Ricardo Tomás

    rctomas wrote:
    Hi,
    In java I’m able to do find the right expression to retrieve what I wantWell, would be nice to tell us what that right expression would be :). Anyway, is this what you are looking for:
    SQL> SELECT REGEXP_SUBSTR(';first field;ir-second field-02;ir-second field-01; third field',';ir-([^;]*)-01')
      2  from dual
      3  /
    REGEXP_SUBSTR(';FIR
    ;ir-second field-01
    SQL> SY.

  • Regular expression - get longest number from string

    I believe it is easy one but I can't get it.Lets say I have a string 'A1_1000' I want to substract the 1000 using regular expression. When I feed Match regular expression I get '1' which is not the longest number. I know other ways of doing that but I want clean solution in one step. Does anybody knows the right regular expression to accomplish that? Thanks!
    LV 2011, Win7
    Solved!
    Go to Solution.

    ceties wrote:
    This is the best solution I was able to come with. I am just wondering if there is "smoother way" without the cycle.
    Since multiple checks are required I would tend to beieve that we do have to loop through the possibilities. in this example
    I start check at offset "0" into the string for a number. Provided i find a number I check if it is longer that any previous number I found and if so save the new longer number in the shift register.
    Have fun!
    Ben
    Message Edited by Ben on 04-15-2009 09:23 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Find_Longest.PNG ‏33 KB

  • Regular Expressions in num-exp

    Hello All,
    I had a problem on my SRST gateway with num-exp insterting a repeating pattern into my 7-digit dialing when in fallback mode.
    For a brief example, the 7digit internal dialing is 21621.. or 21622..
    The num-exp statement of 'num-exp 2... 2162...' was not allowing me to 7-digit dial directly from one IP phone to another while in fallback mode.
    When I dialed 2162154 the 2162 would hit the num-exp and be expended to 2162162.
    I have a work around that uses a voice translation-rule, applied to the call-manager-fallback config that will translate a 7-digit dialed string to the 4 digit dialed string which then hits the 4-digit to 7-digit num-exp and it is working fine.
    However, I was wondering if there is a way to  use regular expressions in num-exp so that perhaps I can skip the intermediate step of using the translation-rule. Based off my existing translation-rules that are working properly, I figured something like this might work for num-exp:
    'num-exp /^2\([12]..$\)/ /2162\1/'
    But when I try to issue a num-exp with a regular expression I get the following message.
    Incorrect format for Number macro pattern
            regular expression must be of the form  ^((\+)?([0-9#*A-F.]|(\\\*))+(\$)?)$
    I have tried a number of different combinations with no success.  I always get the same message.  The regular expression that I tried first was:
    'num-exp ^2... 2162...'
    This is when I first saw the "Incorrect format..." message and figured that is must be possible.  Is this just a generic warning similar to when you try to use complex regular expressions with the 'translation-rule' command vs. the 'voice translation-rule' command and in reality you cannot use regular expressions in the num-exp command?
    Thank you,
    Leo

    Hi Chris,
    Thank you for taking the time to answer my question.  It looks like the answer is no, num-exp does not support regular expressions.
    I don't insist on using num-exp for this I was just hoping to kill two birds with one stone and possibly skip the intermediate step of translating the 7-digits dial to 4-digits using a translation-rule just to expand from 4-digit to 7 again.  This is only an issue while in SRST if a user tries to dial using 7-digits.  We have a 7-digit internal dialing scheme and normally my num-exp is just to expand the 4 digits sent from the telco to our 7-digit internal dialing.  The problem is that both our prefix and part of our DID range start with 21 so while in SRST if a user tried to dial a 7-digit DN, say 2162154, after they dialed the 4th digit (2162) that pattern would hit the num-exp and get expanded to 2162162.  I was hoping to create a num-exp using a regular expression that would only expand a four digit string that begins with a 2 to seven digits and not any string that begins with a 2.  This would 1) expand the four digits sent from the telco and 2) not match a seven digit string that begins with a 2 such as 2162154 which may be dialed by a user.
    Again, this is only an issue while in SRST and I have a pretty good work around so I'm fine with not being able to use a regular expression as part of my num-exp config.  I just thought it would be a cool application of a regular expression if it was possible.
    Thanks again for answering my question.
    Leo

  • Item Validation using Regular Expression

    Hi,
    I am trying to apply a Validation to a text field item, with the type as Regular Expression.
    The text input into the field should be in a HH:MM:SS format, ie 05:30:00 (for 5:30am).
    The text I am placing in the 'Validation Expression 2' box is:
    [0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]
    This doesn't seem to work and I get an error message when I enter text in the correct format.
    I have even tried to use other comparisons, for example:
    or
    .{8}
    but these still give me an error message.
    Anyone have any ideas?

    Thanks for your help Flavio, the Regular Expression tool is really helpful.
    When I use this tool to compare strings with my regular expression, I get output = TRUE, which means I'm getting it right, but for some reason when I copy the same Regular Expression syntax into APEX, it doesn't work.
    I try to input correct strings into the field that is validated by the Reg Expr, but it still gives me an error.
    It seems to be something I am doing wrong within the application, but I can't figure out what I'm missing.
    I am creating an Item Level Validation with details:
    Type: Regular Expression
    Validation Expression 1: P23_BUS_DAY_COVERAGE_START
    Validation Expression 2: ^(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]$
    Has anyone had similar problems using regualr expression validation in APEX?

  • Regular Expressions - Addressbook conversion

    Hi Gurus,
    I am struggling with the following task. I have an addressbook export in the following format and I need to convert it to use the addresses in Eudora.
    I need to do this pretty often. To do away with having to edit the files manually, I am trying to write a Java program using regexp that would take the input file and write out the output file as specified.
    Could someone please advise me on the appropriate regular expressions to get this done?
    TIA.
    Cheers,
    Shanzee.
    Input address file format
    "John","Michael","Kane","[email protected]"
    "Barbara","","Potter","[email protected]"
    "Richard","","Simpson","[email protected]"
    "Graham","T","Laver","graham.t.laver@my_mail.com"
    "Beat","","Henderson"
    "Technology Service Desk"
    Output address file format
    alias "John Michael Kane" [email protected]
    alias "Barbara Potter" [email protected]
    alias "Richard Simpson" [email protected]
    alias "Graham T Laver" graham.t.laver@my_mail.com
    ** delete all rows not having email addresses **

    Hi,
    I guess you are using JDK 1.4 or later. Look at split
    in the String class. And then split your line at ","
    Check how many parts you get (to see it the row has an
    e-mail address or not), and then write the data to
    file.
    /KajMany thanks Kaj.
    I'm using JDK 1.4.2. I was looking for a 'smarter' solution using RegExp :-) But, nevertheless, if I don't get a good suggestion, I'll go ahead and implement this.
    Cheers,
    Shanzee.

  • Online chat, Nov. 12, on Regular Expressions

    One of the new packages added in J2SE v 1.4 is java.util.regex , which provides classes for handling regular exprssions. A regular expression is a string pattern that can be used to perform sophisticated string searching and replacement. Learn more about java.util.regex and regular expressions, and get questions answered in this chat with Sun engineers Michael McCloskey and Mark Reinhold. The chat is scheduled for Tuesday, November 12 at 11:00 A.M. PST/7:00 P.M. GMT.
    To join the chat, go to http://developer.java.sun.com/developer/community/chat/index.html and click on "Join the current session".

    Is there an agenda? Or can we ask anything, e.g.
    about the ActiveX bridge?There is no agenda. You're free to ask any question related to Java Plug-In Technology during the chat.

  • Do J2ME support Regular Expressions?

    If yes, how can i do that
    i want to get a html page by the j2me
    and use Regular Expressions to get all link from it (eg. http://yahoo.com/123.php )

    you can write your own code to do it parsing the text using a blank space to separate words, then analize them. I guess sun wont support regular expressions sooner but you can code it if needed.

  • Regular Expression help required

    {color:#000000}Hi....
    I am having a product table in oracle with products like CZS20T and CZSS30T and so on....
    But for printing on the invoice we need only the product name without the micron thickness like CZS and CZSS{color}{color:#000000}
    I tried regular expression with....."select regexp_substr('CZSS20T','([[:digit:]]{2})') from dual"
    {color}
    and the result was "20"*...*
    But I cant figure out how to use regular expression to get only the product name.
    Maybe there is another way without using Regular exp...
    Please help....

    regexp_substr (prod, '[[:alpha:]]*')and an example:
    SQL> with x as
      2  ( select 'CZS20T' prod from dual union all
      3    select 'CZSS30T' from dual union all
      4    select 'A10CSD' from dual
      5  )
      6  select prod
      7       , regexp_substr (prod, '[[:alpha:]]*')
      8    from x
      9  ; 
    PROD    REGEXP_SUBSTR(PROD,'[[:ALPHA
    CZS20T  CZS
    CZSS30T CZSS
    A10CSD  A
    SQL> Edited by: Alex Nuijten on Jan 27, 2009 8:52 AM

  • Regular expression not giving the required output.

    Hi , I have msgs that look like this :
    dear john smith you Bought 500 shares of Nile Cotton Ginning at 14.9 L.E On 21/01/10
    Im using the Regular expression to get 4 substrings of this msg
    1-Bought|Sold
    2-Quantity of shares (ex: 500)
    3-Name of the stock (ex:Nile Cotton Ginning)
    4-price (ex:14.9)
    Here is my code , but the output returns the whole msg back :
    select SMSID,SMSNO,CUSTOMERACCOUNTID,SENDDATE,ENTRYDATE,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\1')),'(watheeqa)') buy_sell
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\2')),'(watheeqa)') amount ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\3')),'(watheeqa)') company ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at ([0-9]*\.[0-9]*|[0-9][^A-Z][^a-z]) .*','\4')),'(watheeqa)') price
    from SMSOUTMSG@bimsic s
    where trunc(SENDDATE) = trunc(sysdate) -1
    and exists (select 1 from PHONEDETAIL@bimsic p
                where s.CUSTOMERACCOUNTID = p.CUSTOMERACCOUNTID
                and SMSFLAG = 1);Thanks.

    It does check it out
    with t
    as
    select 'dear john smith you Bought 500 shares of Nile Cotton Ginning at 14.9 L.E On 21/01/10' smstext from dual
    select
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\1')),'(watheeqa)') buy_sell,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\2')),'(watheeqa)') amount ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at (.*)','\3')),'(watheeqa)') company ,
    regexp_replace(trim(regexp_replace(SMSTEXT,'^.* you (Sold|Bought)(.*) of (.*) at ([0-9]*\.[0-9]*|[0-9][^A-Z][^a-z]) .*','\4')),'(watheeqa)') price
    from t

Maybe you are looking for

  • Urgent : Doubt in writing a code in start routine

    Hi all ,              I am BI 7.0 system , I have doubt in writing a code in start routine . 1) i have to extract the data first from a custom table based on one condition and then placing it into internal table . 2) Now i have to loop at source_pack

  • Safari isn't loading.  What should I do?

    When I open Safari, it doesn't load.  The load bar stays about 1/10 loaded and the pointer pinwheels.  I thought at first it was my homepage, but I am able to access that same page in both Google Chrome and Firefox.  I am connected to the internet -

  • Itunes 11 "go to current song" not working?

    New layout in "albums" is cool.  However I want to let iTunes shuffle my library while I'm working with other things, and I expect iTunes should "go to current song" to display the album song list (and artwork) in which it's playing. Now I have to pr

  • Reprocess XML messages

    hi all, We have some xml message which were succesfully sent from the xi as idoc, however the idoc failed in r/3 system. The status in xi for the xml message is succesful,in SXMB_MONI. we cud not reprocess the messages. How can i do reprocess the doc

  • RSA3 gets results - but InfoPackage not!

    Hey all, we got the following problem: We are using a generic datasource which is extracting data from two database-views with help of a function block we derived from the SFLIGHT-example. The extraction is working well in RSA3 and we do get the resu