Regex: Alternation in lookbehind group

Hello,
when i use an expression with an alternation, then i expect that the first matching expression will be taken and all others ignored. this is what java does normally (in my experience until now always).
Ok now i try this in a lookbehind group. I have the following expression:
(?<=(Hello World|World))\s\d{4}And the following text:
Hello World 2000Now I expect, that group #1 will return "Hello World", which is the first matching option in the alternation. But i get just "World". It seems that the engine always finds the shortest matching option. Maybe this is a bug (I'm using Java 6)?
My Problem is, I need the longest matching option. Any idea, how this could be done in a lookbehind group?
Thanks!

tm001 wrote:
Hello,
when i use an expression with an alternation, then i expect that the first matching expression will be taken and all others ignored. this is what java does normally (in my experience until now always).
Ok now i try this in a lookbehind group. I have the following expression:
(?<=(Hello World|World))\s\d{4}And the following text:
Hello World 2000Now I expect, that group #1 will return "Hello World", which is the first matching option in the alternation. But i get just "World". It seems that the engine always finds the shortest matching option. Maybe this is a bug (I'm using Java 6)?
My Problem is, I need the longest matching option. Any idea, how this could be done in a lookbehind group?
Thanks!I don't understand why you need the alternation as you have it. You are asking the engine to look back, one character at a time, from \s\d{4} for "Hello World" or "World". This means "World" will always be found first. The engine has no reason to keep looking for other matches because it already found something your expression says is acceptable. Seems reasonable to me. Where does it say the engine must match the longest string in an alternation? How did you come to form this expectation.

Similar Messages

  • Regex Matching on Capture groups

    I have this regular expression:
    (throw|give)(?: ([1-3][A-B]))+
    given this input:
    throw 1A 2C 1B 3C
    How would I capture each of the items 1A 2C 1B and 3C?
    In the above expression I have 3 capture groups
    group0: whole expression
    group1: (throw|give)
    group2: ((?:1|2|3)(?:A|B|C))
    The problem is that when I execute the find() on my matcher it tries matching the whole expression at once! That means for the group 2 I always get the last match only:
    group0: throw 1A 2C 1B 3C
    group1: throw
    group2: 3C
    How do I get the matcher to only match on ONE capture group at a time?! Is it possible? I thought that was the purpose of the find() method. The documentation says find() matches on a "subsequence", yet I can only get it to match on the whole expression. Plus, I don't see where "subsequence" is defined in the documentation. What am I missing here?

    "Attempts to find the next subsequence of the input sequence that matches the pattern." (my emphasis)
    find() matches the whole regex, not components thereof. What you need to do is use one regex to match the whole expression and return a capture group with the digit-letter pairs, and then use another regex on that capture group to extract the pairs one at a time.*******************************************************************************
    Answer provided by Friends of the Water Cooler. Please inform forum admin via the
    'Discuss the JDC Web Site' forum that off-topic threads should be supported.

  • OUD DPS alternative for DSEE Group Filters

    Hi,
    I would like to know what is an alternative for group dn filter within OUD DPS mode against DSEE DPS. How can we set up this functionality within OUD DPS mode, any pointers will be helpful. I would like to create a network group which will allow access to users having association to a particular group.
    Thanks.
    group-dn-filters                        :  cn= Access Group,ou=groups,o=example.com 
    group-search-bind-dn                    : uid=access-group-user,ou=People,o=example.com 

    Hi Sylvain,
    The use case is something like this :
    We've several LDAP Servers specially for reporting purpose, based on the functionality as listed below members of "cn= Access Group" group will have access to the LDAP Server only, any other users will be redirected to other connection handlers and a different ldap within dsee dps. The group bind dn user as listed below will verify the membership.
    Could you let me know how to accomplish this with Access Control as there will not be any re-routing among the Network Group if things are defined at the Access Level? Can we do this on OUD DPS level?
    group-dn-filters                        :  cn= Access Group,ou=groups,o=example.com
    group-search-bind-dn                    : uid=access-group-user,ou=People,o=example.com

  • How to make regex alternation return first match?

    Hi,
    I have the following string:
    "i am a man and i have a cat and a dog and a bird"
    and I wish to extract the part of the sentence from "man" up to the first occurence of "dog" or "cat". So I wish the extracted sentence to be
    "and i have a"
    or alternatively
    "man and i have a cat"
    I would guess the regular expression "man.*(cat|dog)" should do it, but that seems to always return the sentence up to the last occurrence of dog and cat, when I want the first occurrence. So "man.*(cat|dog)" returns (when using find() and group()):
    "man and i have a cat and a dog"
    Anyone have any ideas how I can return the sentence from (preferably excluding) man and to (preferably excluding) the first occurrence of cat or dog?
    Thanks!
    Message was edited by:
    MagnusGJ
    Message was edited by:
    MagnusGJ

    Take your pick -
            // One  possibility
            String target = "i am a man and i have a cat and a dog and a bird";
            String result = target.replaceFirst(".*?man (.*?)( cat| dog).*", "$1");
            System.out.println(result);
            // and another
            Matcher m = Pattern.compile("man (.*?) (cat|dog)").matcher(target);
            if (m.find())
                System.out.println(m.group(1));
            }

  • Alternative to Group by in oracle 9i

    Dear All;
    I currently have a query which is generating 10,000 rows but when I try applying a simple group by it affects the performance of the query. Hence, is there an alternative to using group by. Thank you.

    but when I try applying a simple group by it affects the performance of the query.If you could show us the query + execution plan with and without the group by, we could have suggestions...
    Adding a GROUP BY to a query that performs nicely, will of course add some additional required cpu processing, but shouldn't necessarily have to change the way the rows that need to be grouped are retrieved.

  • Alternative to Group By?

    Hi
    I have a query that has in its Select the Max function and of course a Group By. Whilst the query itself is returns the correct results, when running this through the correct cost analysis it is showing that the cost is very high. I have checked that it is this combination that is causing this and there are no joins. Therefore, is there alternative to using Group Bys, or is there away to make these kind of queries more efficient?
    Can anyone advise me?

    user633278 wrote:
    It is a general question rather than asking for actual help to an SQL query. My question is whether there is an alternative to GROUP BY and MAX when the cost is high?Sometimes you can quickly get a MAX value of a certain column by using an index.
    For instance, suppose you'd want to get the max salary of all employees working in a certain departement.
    And also suppose you have this index available to you:
    create index emp01 on emp(deptno,sal);Instead of writing this query:
    select max(sal) into pl_maxsal
    from emp
    where deptno = :b1;
    ...This query might perform an index range scan to retrieve all employees in that department and then perform a sort or hash group by to get the max salary.
    You can also write it like this:
    cursor c1(p_deptno number) is
      select sal from emp where deptno = p_deptno order by sal desc;
    open c1;
    fetch c1 into pl_maxsal;
    close c1;
    ..This query might do an index range scan descending, to just get the first row, which will have the max salary of that department.
    Edited by: Toon Koppelaars on May 19, 2011 6:11 AM

  • PS Script to find the list of users and the groups in a Workgroup server

    Hi There, could you please explain on how to get a complete list of local users and local groups in a "Workgroup" server to which they belong to using Powershell. I'm able to get the users list but couldn't find any help in finding
    the script to find to which localgroup the user belong to. Anticipating your response. Also let me know the cmdlet for Win2k3 servers to find the same.

    Here's some code from David Pham (don't remember wher I fund this code):
    Trap {"Error: $_"; Break;}
    Function EnumLocalGroup($LocalGroup)
    $Group = [ADSI]"WinNT://$strComputer/$LocalGroup,group"
    "Group: $LocalGroup"
    # Invoke the Members method and convert to an array of member objects.
    $Members= @($Group.psbase.Invoke("Members"))
    ForEach ($Member In $Members)
    $Name = $Member.GetType().InvokeMember("Name", 'GetProperty', $Null, $Member, $Null)
    $Name
    # Specify the computer.
    $strComputer = gc env:computername
    "Computer: $strComputer"
    $computer = [adsi]"WinNT://$strComputer"
    $objCount = ($computer.psbase.children | measure-object).count
    $i=0
    foreach($adsiObj in $computer.psbase.children)
    switch -regex($adsiObj.psbase.SchemaClassName)
    "group"
    { $group = $adsiObj.name
    EnumLocalGroup $group }
    } #end switch
    $i++
    } #end foreach

  • How to use LSMW using the IDOC to upload and maintain cost center group

    Hi Everyone,
    Is there anyone who knows how to use LSMW using the IDOC functions instead of the recording. I wanted to upload the alternative cost center group I created in the system. 
    reply would be greatly appreciated
    Warm Regards

    Hi Praveen,
    There is a risk trying to migrate data directly into standard tables because this can generate database inconsistences or wrong inserted data according to what is customized in the target system. I do not recommend migrate like this. 
    With LSMW you use objects like direct input programs, idocs, bapis and recorded batch input. Try to create a project and use an standard object for your data. Also, check in SXDA transaction (Goto-->DX programs) if there is a standard program for your data.
    Anyway, if you want to upload data directly to tables, read below thread:
    ["UPLOAD  CSV  FILE";
    [how to upload .csv file into a custom table;
    Regards,
    Roger

  • Where do I find the Group account number in SAP system

    Hi All,
    I have the same problem. I work in a company where all was installed and configured before my arrival and so I always need to do a lot of research to solve a problem.
    I tried somedays ago using txcode FS00 to create a new GL account but got stocked because the system requested a Group Account Number (Consolidation data in Charts of Accounts).
    I do not know where to find this number in the system. After a very long search, I have given up searching and hereby ask for your help.
    Can anyone tell me where to find the Group Account Number in the system. Is there a txcode for this? I tried already OBD4.
    As I am new in the SAP world, a step by step explanation will be appreciated.
    Many thanks in advance

    Hello aolowu
    Group Account Number field has lot of year/period end ramifications. Here is the definition " When you define the balance sheet and PL structures, then accounts are assigned to line items within the balance sheet and PL. This assignment is made either via the G/L account number or alternatively via the group account number given in this field. The usage of the group account number offers the advantage that by specifying a number, a group of accounts can be assigned immediately to the balance sheet or P+L item".  Suggest you work with a FI guy.
    To quickly get over however, you can enter the same number that you are creating in that field. At my current client, I have seen several accounts set up like this, although many of them have a different number there.

  • ActiveSync and Personal Contact Groups for Mobile (incl Windows Phone)

    Hello,
    As more MDM's (including BES10, Airwatch, native Windows Phone etc - besides Good For Enterprise) are moving towards EAS for enterprise e-mail sync, and I myself have 2 devices which have forced me to use EAS, I noticed that the various personal contact
    groups that I've created in Outlook are no longer available from these devices. Only on my BES 7 blackberry torch can I still find the personal distribution lists a.k.a. contact groups (not from GAL, but created in outlook) to appear, probably since it doesn't
    use EAS.Is there a way to enable syncing personal distribution lists? It seems to be a real productivity killer to not have this ability and to try and remember the group's members or select them especially for larger lists each time.
    Thank you

    Thanks for the reply (although the link you provided is referencing using Outlook 2013 for Outlook.com type hosted accounts). My situation is Outlook in an on-prem enterprise Exchange environment but with mobile devices that connect to exchange via EAS.
    If the response is still the same, then my follow up question is - why not? And what is the alternative to "contact groups" in the EAS world?

  • Regex to match all exept at beginning of line

    Hi, is it possible to do this in java?
    I'd like to replace all "+" with "&+", exept if there's a "+" at start of the line
    "dsadsa+dasdsa+das" -> "dsadsa&+dasdsa&+das"
    "+dsadsa+dasdsa+das" -> "+dsadsa&+dasdsa&+das"

    T.B.M wrote:
    (?<! something ) says look behind (<) for NOT (!) something. In the example the NOT is the start of the line (^) . So, if the next character is a '+' but when we look behind we don't see the start of the line then we have a match.Thanks for explaining :-)
    Also, I tested by changing ^ to another regex, it appeared to be working correctly. This means, ^ can be any regex instead of just a character (Can you please confirm?).That is why I said 'something' and not 'character'
    I am asking this because when I tried:
    System.out.println("+123+dsadsa+dasdsa+das".replaceAll("(?<!^\\+123)\\+", "&+"));It worked correctly, but when I tried:
    System.out.println("+123+dsadsa+dasdsa+das".replaceAll("(?<!^\\+\\d*)\\+", "&+"));Following exception was thrown:
    java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 9Does this mean we can use regex, but without quantifiers ?* and + quantifiers are not allowed but {4,7} quantifiers are allowed. There are bugs in the look behind but as long as as you stick to fixed length or range 'something' then you won't hit them.
    >
    Thanks again for explaining!

  • Using Regex to find a string

    Is it viable to use regular expressions with Search "Specific Tag" (i.e.script) "With Attribute" (i.e. src) and "=" a regex string rather than an exact search term?  The Find / Replace tool seems to prevent a simple wildcard find (i.e. "searchter* for searchterm) Any insight would be appreciated.

    uneAaron wrote:
    I'm trying to replace a script source value for all instances where the value contains the string "/bbcswebdav/xid-144702_1", where the string "xid-" is followed by a different numerical value in each instance.
    The regex for finding that string is:
    \/bbcswebdav\/xid\-[\d_]+
    The numerical value contains an underscore, so the final section ( [\d_]+ ) uses a range that selects one or more numbers and/or underscores.
    Perhaps as important as identifying what you want to find is specifying how you want to replace it. Regexes can have capturing groups that can be used in the Replace field to simplify matters.

  • Partial substitution of alternative item material

    Dear guru.
    I have a  bom  with two alternative item (A and B) with same group.
    I need that mrp create dependent requirement only for A and nothing for B.
    After atp check if B is available and A isnu2019t available I need that the system create requirement for B for the available quantity and create requirement for A for the remained quantity.
    How can I set the alternative item data group of bom for these two component ?
    Thanks.

    Hi,
    I hope that I understood you right;
    The set up of the alternative item group in the BOM should be like this:
    Priority - 1 for A, 2 for B
    Strategy - 1 for both
    Usage Prob. - blank for both
    Alternative item group - same for both
    Now this works like this:
    MRP will always plan A.
    When ATP is checked in production order it looks first for A. If A not available or available quantity not enough, then it looks for B.
    Be aware of system behavior when using this with backflush and overproduction! There is a note on this!
    Regards,
    Mario

  • Table of contents - alternating background colour

    Hey all,
    I'm trying to create a table of contents that has an alternating grey/white background for title. I have one level of headings
    I worked out that you can apply alternating paragraph style groups to text blocks, but I'm not sure it's possible to do that with a table of contents.
    Any ideas on how to do this would be very appreciated.
    Thanks.

    Peter's proposal is so simple and clever that it's a good way to play it! 
    But need to play it again when update as said Ariel!
    [Sample that works if max. 2 lines paras, using para rules]

  • Item Category do  ot change for sub-item in BOM

    Hi Friends
    I create main item using MM01, Gen item cat. grop in basic data 1 in ERLA and Item cat. group in Sales org. 2 is LUMF
    and similarily i created other items useing MM01 (for making sub item of main item) Gen Item Cat grop in basic data 1 is NORM and Item cat group in Sales Org. is also NORM.
    When i create sales order (OR) and enter main item only, when i press enter (green button at right top), BOM automatically explode and Item Category of main item change to TAP main item become in display mode BUT ITEM CATEGORY of sub items do not change (it remains the same as TAN), i should also change to TAE
    and also when i save this document it shows error at bottam that prising PR00 is missing. When i edit and give price of each sub item, i can save document and all prices which i am giving just now is automatically added in net value at header lavel.
    Please any one can advice me where i am doing wrong
    Rajesh
    Email: [email protected]

    HI,
    Please check in customizing.IN assign item category menu
    S.doc typeitem cat. groupUsageHigh lvl itemiem cate.
    ORERLA   TAQTAE.
    IN MM01 ERLA and LUMF can not be assigned to same material.They are alternative item category group.
    ERLA  is used when you want to price Main item  in BOM and sub-item are not priced.
    LUMF is used when main item in BOM is not priced but sub-item(individual component) are priced.
    In SAles org vie 2- you have assigned LUMF,that is each sub-item is priced.hence you are able save the document.Since  You have  maintained price in VK11 for each sub-item and item category of sub-item is not getting vhanged from TAN to TAE.
    But if you maintained ERLA in Sales org view 2 and redo all steps,your problem will be solved.
    vrajesh

Maybe you are looking for

  • Spinning wheel of death is killing me. Have some info that might help.

    Started occurring about a week ago. It happens whether I am running several applications or just surfing internet. Seems to get progressively worse the longer I have computer on. I usually eventually have to power off. Happens regardless of which use

  • Check on open items during payment

    Hi experts. When we release payment to vendor system show all open items whether these are due or not due. Is  there any check available by which system show only due items . Regards Parkash Chand

  • 11.0.3 11x17 multi page bug

    I recently upgraded everyone from a wide range of versions to 11.0.3 with a group policy.  This wasn't a problem in the past. Details Multi page PDF, all pages are 11x17 Windows 7 Pro x64 PCs Symptom When printing the first page it prints the first p

  • Brush's radius problem Please help!

    Hello everyone. I am about to edit a photo which is RGB 8bit and I am expanding the background and putting few body figure toghetehr but I just noticed that when I use my brush in low opacity it leaves the brush's radius and I can see them in the art

  • Email set up on blackberry 9300

    hi, i was wondering if anyone can help my blackberry won't let me set up my email accounts everytime i fill in all the details it says that either my email or password is invalid for both my email accounts but it works fine on the internet it says to