Regular Expression  Multiple grouping

Dear all
I want to do a grouping of multiple criterias as expression .
Single grouping is possible , but when group within a group comes things doesnt work for me.
User would define the comibination
For example i have 4 criterias
C1
C2
C3
C4
Basic grouping works for example :
(C1&C2) | (C3&C4)
Complicated grouping i have no idea how to implement it.
(((C1&C2) | (C3&C4))&(C1&C2) )
I need validate if the expression is correct and need to pick up all the groups and do the AND or OR.
Any help woul dbe appriciated
Regards
pacs

You cannot use regular expressions for this since there can be nested parenthesis which is out of the scope of regex-es.
Continued here: [http://forums.sun.com/thread.jspa?threadID=5418262]

Similar Messages

  • Regular expression: multiple possible matches, find all?

    Hi, I'm looking over something I'm afraid, the solution to my problem will probably be simple :(
    Consider the input string "something aname bname something"
    I have a list of other strings that might occur in the string:
    "aname"
    "aname bname"
    I want to know if any of the strings in the list occurs in the input string, possibly both.
    For this, I created the pattern "(?i)(aname)|(aname bname)(?i)"
    With a Matcher, it will only match the "aname", while I want to find both the "aname" and the "aname bname".
    Reversing the pattern, "(?i)(aname bname)|(aname)(?i)", it will only find "aname bname", and not the single "aname".
    I cannot really create a very sofisticated pattern such as "(aname( bname)?)", since the list of strings comes from a database. Creating a very nice pattern by looking at the possible matcher strings before compiling the pattern is not really a clean solution.
    Again: what is my at-this-point-non-functional-brain missing? Thanx!

    Thanks for the link. Of course I have read the manual, I guess there is something wrong with my eyes because I don't immediatly see the answer. Last weekend I already ordered new glasses, but they take three to four weeks to deliver my new glasses. Could you in the mean time point me to the exact place I should look?
    In all seriousness, I already tried the Matcher. It's the pattern itself that causes it to match only the first alternative in the list of groups in that pattern. I did read the Pattern manual here.
    My test code:          String input = "something aname bname";
              String match1 = "aname";
              String match2 = "aname bname";
              String quotedPattern = "(?i)(" + Pattern.quote(match1) + ")|(" + Pattern.quote(match2) + ")";
              System.out.println(quotedPattern);
              Pattern p = Pattern.compile(quotedPattern);
              Matcher m = p.matcher(input);
              while (m.find()) {
                   for (int i = 0; i < m.groupCount() + 1; i++) {
                        System.out.println("Group " + i + ":\t" + m.group(i));
              }Outputs:
    (?i)(\Qaname\E)|(\Qaname bname\E)
    Group 0:     aname
    Group 1:     aname
    Group 2:     null
    The last matching group should also match in my opinion. If I turn the pattern around, i.e. first "aname bname" and then "aname", it will still only find "aname bname" and not "aname", which would also match.
    Thanks again

  • Regular expression for 2nd occurance of a substring in a string

    Hi,
    1)
    i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
    Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
    in this i want the second occurance of afn and change that one only...
    which regular expression i have to use...
    Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
    2)
    How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
    substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
    Thanks in advance,
    Venkat

    javafreak666 wrote:
    Hi,
    1)
    i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
    Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
    in this i want the second occurance of afn and change that one only...
    which regular expression i have to use...
    Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
    2)
    How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
    substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
    Thanks in advance,
    VenkatWhat do you mean by using a regex to get the index of a second substring? There is not method in Java which uses regex to et the index of a substring.
    There are various indexOf(...) methods for this:
    String text = "axe,afn,sdk,jdi,afn,mki,mki";
    String target = "afn";
    int second = text.indexOf(target, text.indexOf(target)+1);
    System.out.println("second="+second);Of course you can find the index of a group like this:
    Matcher m = Pattern.compile(target+".*?("+target+")").matcher(text);
    System.out.println(m.find() ? "index="+m.start(1) : "nothing found");but there is not single method that handles this: you'll have to call the find() and then the start(...) method on the Matcher instance, so the indexOf(...) approach is the favourable one, IMO.

  • Esing regular expression to reformat text (match & replace)

    Hi guys ..I am using regilar expression to reformat logs files..
    this is how i match the pattern..
    Pattern pattern = Pattern.compile("^<[^>]*>(.{6}).....
    Matcher matcher = pattern.matcher(thisLine);
    then prints the output...
    myOutput.print(matcher.group(1));
    It works..however my prob now is, i am reading a date in format "8 Nov"
    How can i change this to 8-11-2005 ????

    hmmm....ya..i can see the idea
    (\\d\\d?) (Jan|Feb|Mar|Apr|May|Ju[nl]|Aug|Sep|Oct|Nov|Dec) means that the month can be either one rite?
    but the thing is..its collected and put in a group. for example:
    Pattern pattern = Pattern.compile("^<[^>]*>(.{6}) ...
    myOutput.print(matcher.group(1));
    the first regular expression is group in group(1). its working..it can detect the text in group(1) the problem was...i tried this..
    String priority = matcher.group(6);
                   if (priority=="3")
                        System.out.print("AAA\n");
                   else
                   System.out.print("BBB\n");
    it keeps on printing BBB even there is a "priority=3".

  • Get all groups from a regular expression match

    Please help me understand how to use Java regular expressions:
    I have an expression similar to this:
    {noformat}"([^X]+)(X[^X]*)+"{noformat}This should match stuff like "asaasaXdfdfdfXXsdsfd".
    How does one access all the matches for the second group (the second groups has a Kleene operator
    added so it is not really just one group --- but match.groupCount() is always 2)
    Here is roughly the code:
    {noformat}java.util.regex.Pattern pattern = {noformat}{noformat}java.util.regex.Pattern.compile({noformat}{noformat}"([^X]+)(X[^X]*)+",{noformat}{noformat}java.util.regex.Pattern.MULTILINE{noformat}{noformat});{noformat}{noformat}java.util.regex.Matcher matcher = pattern.matcher(text);{noformat}{noformat}matcher.find();{noformat}{noformat}int groupcount = matcher.groupCount();{noformat}
    Also, without matcher.find() I get an illegalStateException .. which I also get if I use matcher.matches() instead
    of matcher.find().
    I am obviously missing something here. There is always at least one "X" in the string so shouldn't that pattern always
    match the whole string? Since there are often multiple X, shouldnt I get a group for each occurrence of X, followed
    by 0 or more other characters?
    {noformat}But when I try to match everything by using "^([^X]+)(X[^X]*)+$" I get an "IllegalStateException: No match available" again.{noformat}
    What is the correct way to do this?
    Edited by: johann_p on May 16, 2008 10:39 AM

    I am sorry I messed this up. Here is a SSCCE:
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    class RegExp1 {
        public static void main(String[] args) {
          String testString = "first|aaaa | bbbb\n|cccc|ddddd";
          Pattern pattern = Pattern.compile("^([^|]+)(\\|[^|]*)+$");
          Matcher matcher = pattern.matcher(testString);
          matcher.find();
          int groupcount = matcher.groupCount();
          System.out.println("Found "+groupcount+" groups");
          System.out.println("Matcher: "+matcher);
          for (int i = 1; i <= groupcount; i++) {
            System.out.println("Match "+i+": "+testString.substring(matcher.start(i),matcher.end(i)));
    }I figured out a small bug in my first code that explains some of the exception oddities, but my principal question remains:
    how do I access all the matches that correspond to the second capturing group?
    In the example I would get "first" for Match 1 and "|ddddd" for Match 2, but how do I access all the matches??
    Thank you for your help!

  • Java – Regular Expressions – Finding any non digit byte in a multiple byte

    Hello,
    I’m new to JAVA and Regular Expressions; I’m trying to write a regular expression that will find any records that contain a non digit byte in a multiple byte field.
    I thought the following was the correct expression but it is only finding records that contain “all” non digit bytes.
    \D{1,}
    \D = Non Digit
    {1,} = at least 1 or more
    Below is my sample data. I would like the regular expression to find all of the records that are not all numeric. However when I use the regular expression \D{1,} it is only finding the 2 records that all bytes are non digits. (i.e. “ “ and “A “)
    “ 111229”
    “2 111229”
    “20091229”
    “200912c9”
    “201#1229”
    “20101229”
    “20110229”
    “20111*29”
    “20111029”
    “20111229”
    “20B11229”
    “A “
    “A0111229”
    Please note I have also tried \D{1,}+ and \D{1,}? And they also do not return my desired results
    Any assistance someone can provide would be greatly appreciated.

    You don't show the code you are using but I surmise you are using String.matches() which requires that the whole target must match the regular expression not just part of it. Instead you should create a Pattern and then a Matcher and use the Matcher.find() method. Check the Javadoc for Pattern and Matcher and look at the Java regex tutorial - http://docs.oracle.com/javase/tutorial/essential/regex/ .
    P.S. You can re-use the Pattern object - you don't have to create it every time you need one.
    P.P.S. Java regular expressions work with characters not bytes and characters are not not not bytes.

  • Regular expressions and capture groups

    Hi everyone :)
    Is there a way to override the default behaviour of capture groups in regular expressions? More specifically I want to override this:
    "The captured input associated with a group is always the subsequence that the group most recently matched."
    For example, if I have a string that is this:
    * <comment one>
    * <comment two>
    <some text>
    I have a pattern of the form "(.*)(/\\*.*\\*/)(.*)" which will match multi-line comments. I have also specified the flag DOTALL so that the predefined character class '.' matches over line-breaks.
    If I apply this pattern to the above string I get comment two being captured, not comment one. This is because of the stipulation that I cited above.
    I need to be able to capture only the first match, and prevent the capture group from being overwritten by more recent matches.
    Is this possible? Any ideas?
    Thanks in advance.
    Kind regards,
    Ben Deany

    Is there a way to override the default behaviour of
    capture groups in regular expressions? More
    specifically I want to override this:No, but you don't need to.
    I have a pattern of the form "(.*)(/\\*.*\\*/)(.*)"
    which will match multi-line comments.Comment two is captured by the second group because comment one is eaten by the first group. Use the reluctant quantifier "*?" on the . in the first group instead of the greedy quantifier "*" to get what is apparently the behavior you want. Then the first group will contain nothing, the second group will contain comments one and two, and the third group will contain the following text.
    .* is a very powerful thing to use. It will match everything in its path, guzzling text like moonshine at Mardi Gras. The only reason it doesn't match comment two as well is because then the expression as a whole would not match.
    The parentheses surrounding the first and third groups are not needed (unless you want to use group methods on them too).

  • Regular expressions with dates and multiple matches

    I am currently attempting to automate modifying start and end dates within a .config file via powershell but I am having issues identifying the regular expression for the end date section since both are on the same line in the file. Below is the string that
    I want to change.
    Sometimes the dates are blank and sometimes the dates are filled in.
    Dates are always in the same format (yyyy-MM-dd hh:mm).
    I also want to note that there are multiple instances of 'StartDate="" EndDate=""' for other applications throughout the same config file so I cannot limit the expression to not include the App name. 
    I do not want to limit the search to a line number since there are instances where admins will add an extra space in the config file that may throw off the line number.
    I want to replace the dates or lack there of in their respective spots on the line below via powershell:
     <App name="TestApp" StartDate="2012-03-22 13:30" EndDate="">
    I am successfully able to use 
    $startRegex = '(?<=<App name="TestApp" StartDate=")([^"]*)'
    to replace the StartDate but I can't seem to single out the EndDate with regular expression. What expression can I use to have it ignore what is in the quotations after StartDate and only pay attention to the EndDate value?
    Below is a snippet: 
    $path = d:\inetpub\website\app.config
    $startRegex = '(?<=<App name="TestApp" StartDate=")([^"]*)'
    $starttime = (get-date).ToString("yyyy-MM-dd hh:mm")
    (gc $path) -replace $startregex, $starttime | set-content $path
    I want to accomplish the same for EndDate.
    Thanks in advance!

    If you do this with XML it will be painless and less prone to error.
    $n=$xml.SelectSingleNode('//App[@name="TestApp"]')
    $n.StartDate=$newstartdate
    $n.EndDate=$newenddate
    $xml.Save($filename)
    \_(ツ)_/

  • Grouping & Back-references with regular expressions on Replace Text window

    I really appreciate the inclusion of the Regular Expressions in the search & replace feature. One thing I am missing is back-references in the replacement expression. For instance, in the unix tools vi or sed, I might do something like this:
    s/\(firstPart\) \(secondPart\) \(oldThirdPart\)/\2 \1 newThirdPart/g
    which would allow me to switch the places of firstPart and secondPart, and totally replace thirdPart. If grouping and back-references are already present in the Replace Text window, how does one correctly invoke them?

    duplicate of Grouping & Back-references with regular expressions on Replace Text window

  • Regular Expressions - replace inner group

    I'm trying to do the following:
    1. Given the following string:
    Truth, like tumors, require a cut to be removed.
    2. Grab the whole sentence and the following:
    like tumors
    3. Replace "like tumors" with "like posion" and add one line to the sentence like so:
    Truth, like posion, require a cut to be removed.
    To be free you must endure pain for a season to finally be free from it.
    I can grab the sentence with reg expressions, I can even grab the second search (#2) in a group, I'm just wondering if there is an elegant way to replace both at the same time. I could always replace one then search and replace the next, but that seems redundant since I can grab both the first time around. Any help?

    according to:
    http://javaalmanac.com/egs/java.util.regex/GroupInRep.html?l=find
    // Compile regular expression
    String patternStr = "\\((\\w+)\\)";
    String replaceStr = "<$1>";
    Pattern pattern = Pattern.compile(patternStr);
    // Replace all (\w+) with <$1>
    CharSequence inputStr = "a (b c) d (ef) g";
    Matcher matcher = pattern.matcher(inputStr);
    String output = matcher.replaceAll(replaceStr);
    // a (b c) d <ef> gthis should be exactly what you're looking for.

  • How to Capture Multiple Line String using Regular Expression?

    Hi, 
    I have a simple program like this:
    What I want to accomplish is to capture everything between >>start and >>end using a single Match Regular Expression node. It seems that setting multiple? to True or False does not help.
    I am using LabVIEW 2012.
    If it is impossible to capture it using a single node, that is fine. But I want to make sure that I can make full use of this node without combining serveral others.
    Thank you!
    TailOfGon
    Certified LabVIEW Architect 2013
    Solved!
    Go to Solution.

    Thank you for the fast response! Your solution worked in the example case
    After I saw your post, I was finally able to step forward. But I still wanted to make use of dot notation due to the limitation of characters that match with \w. 
    I made some more modification to your regular expression then now it seems working for all characters:
    >>start((?:\s|.)*)>>end
    Thanks!
    TailOfGon
    Certified LabVIEW Architect 2013

  • Regular Expression for multiple emails

    Hi! I have a jsp page that has an inputTextArea so the user can enter multiple email addresses. In the backing bean (after they submit) I tokenize thru it and add email addresses to an arraylist. I want to validate that they are correct format before adding to arraylist, but how do I do that in the backing bean? All regular expression examples I have seen are in jsp page and javascript. Any sample code / suggestions would be greatly appreciated - as I have not had much experience with regular expressions. Thanks!

    Hi,
    this could be a solution for your problem; I've created two regular expressions to find valid email- and http-addresses in fulltext or xml-text fields ;-)
    HTTP:
    (\\s|>|^)(?!(@|/|\\.))(http://|https://|ftp://|sftp://|www\\.)([A-Za-z0-9_-]{2,}\\.)+[A-Za-z]{2,4}[:]?(/|\\?|\\&|\\;|\\%|=|\\.|\\#|_|-|[A-Za-z0-9])*(?!(@))(?<=([A-Za-z0-9=]+))(\\s|\\W|_|<|$)
    eMail:
    (\\s|>|^)(?!(:|www\\.|\\.))[A-Za-z0-9_.-]+@([A-Za-z0-9_-]+\\.)+[A-Za-z]{2,4}(\\s|\\W|_|<|$)
    sincerely
    Hans Georg Filipp

  • Regular Expression for allowing user to add multiple email id's

    Hi ,
    right now i'm working on regex in javascript and which accepts only one single email id
    Can any one help me with a Regular Expression which accepts multiple email id's in the "To" field.

    Try this:
    /^[\w.-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|bi
    z|info|name|aero|jobs|museum)(?:[,;
    ]+[\w.-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|inf
    o|name|aero|jobs|museum))*$/i..this is want i was trying to achieve....Thank you
    very much, it worked perfectly.Hi friends,
    I wanted to share with you all , the regex I have written
    regex works perfectly fine...valid delimiters are "," & ";" i (either of comma or semicolon):-
    /^[\w\.-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|jobs|museum)((,|;)[\w\.-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|jobs|museum))*$/i
    thnx,
    madhun

  • "Multiple Line" Regular expressions in find/replace

    Hi there,
    I'm wondering if it is possible to find and replace (in batch
    mode) the following obstacle:
    say is have this piece of code in every html file i'd like to
    edit:
    <html>
    <blah blah (Same text in all files)>
    <blah blah (NOT same text in all files)>
    <blah blah (NOT same text in all files)>
    <code that is the same again in all files>
    and would like to replace it by nothing, effectively deleting
    the part completely... (by leaving the replace by field empty).
    The tricky part is that the lines which are NOT the same in
    all files, are sometimes 2 lines, but sometimes 3 or more lines.
    Somehow I need to get the regular expression to include
    <line>* (or something similar), in order to make the regular
    expression work.
    Any ideas on how to solve this? I must say untill now, the
    Dreamweaver search and replace function has been the most effective
    one, compared to many alternatives out there.
    Rp

    I've tried \1 and $1Just these in the text items of the find & replace dialog box...?????
    Can you write down exactly what have you tried....(text to be replaced by which....)????
    Greetings....
    Sim

  • NIRG LabVIEW regular expression for covering multiple requirements

    The Word document type in NI Requirements Gateway allows for comma separating the requirements in a Reference / coverage statement.  I would like to do the same within my LabVIEW code, but the type does not have the same Sub regular expression field available.  Is there any way to have a LabVIEW regular expression find coverage statements such as the following:
    [Covers: REQ-5, REQ-9, REQ-15]
    currently within LabVIEW comments I have to have 3 separate [Covers: REQ-5] type statements

    cdweiss,
    I'm very interested to know if you have any other feedback on NI Requirements Gateway.  I'd also be curious to know what products are you're using with it and how extensive your requirements are.
    Feel free to email me directly at [email protected]
    Cheers,
    Eli 
    Message Edited by Elijah K on 01-19-2010 11:40 PM
    Elijah Kerry
    Senior Product Manager, LabVIEW
    Follow my Software Engineering for LabVIEW Blog

Maybe you are looking for

  • How to create a magnifying glass for image details

    hello, i am displaying an image with high resolution,so that the image on the screen has not the real resolution. to look at details i want to move the mousepointer over the image and in an area under the mousepointer there should appear the related

  • How to use image from a file in signature appearance.

    Hi, I am creating a Plugin for acrobat 9, using PubSec using DocSign sample as basis. I have created the appearance using text objects and the logos data that came with the DocSign sample. But I want to use image from a file (like, jpg) in the signat

  • Presentation Layer Property

    Hi experts, In administratrion tool for obiee 10g, there are some property,such as export logical keys ,impilict fact column, in presentation layer. Can anybody tell me what it is and how to use it? Thank you.

  • Am i able to transfere data from iphone to ipad

    I am planing to purchase a new ipad, and i want to transfere my content of the iphone to it. Is it posible to do that through the PC, or the blutooth, without internet connection ?.

  • Rescue & Recovery can't see backups any more

    Hi!  (new here, so hello all!) I have been using R&R on my T420 (Windows 7, 64-bit) for a while now, carefully backing up my C:\ to an external USB drive every few weeks, or when I install something major.  I had 29 backups on the disk.  The disk is