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.

Similar Messages

  • Capture regex match as a variable?

    Hello!
    I have this program and I basically want to match a part of a string and grab the match as a variable. In this case, the string I need to parse is 'foo'.
    Here is what I have:
    public class Test
         public static void main(String[] args)
                    // link <link> format
              String foo = "http://www.foo.com <http://www.foo.com>";
              String the_regex = "\\<(http://[^\\>]*)\\>";
              String the_replacement = "<a href=\"$1\">$1</a>";
              System.out.println(foo.replaceAll(the_regex,the_replacement));
    }$1 (sorta like PERL) should be the captured text from the_regex
    Any ideas?
    Thanks in advance.

    Dubwai - I think I got it, thanks for the guidance. Here is what I used, and it seems to work. Thanks!
    public class Test
         public static void main(String[] args)
              String foo = "http://www.foo.com <http://www.boo.com>";
              String regex="\\<(http://[^\\>]*)\\>";
           Pattern p = Pattern.compile(regex);
           Matcher m1 = p.matcher(foo);
           while (m1.find())
             System.out.println("The site = " + m1.group(1));
    }

  • Regex capture groups in IdocScript

    Hello,
    I'm looking for a way to print out capture groups as part of a regex match using Idoc Script. Here's a basic example of what I'm trying to do.
    HTML:
    <p>This is a paragraph of text</p>
    Idoc Script:
    <!--$r = wcmElement("regexText")-->
    <!--$if regexMatches(regexText, "<p>(.*)</p>")-->
    <!--$firstParagraph = $1-->
    <!--$endif-->
    Essentially, what I'm trying to do is store the value between the <p></p> tags in a variable. I know there's a syntax error in my above script, but the IdocScript documentation does not touch on capture groups at all, so I'm left to guess on what I know from other scripting languages.
    Thanks,
    Josh

    <p> tags are escaped and ssIncludeXML will not do the trick.
    you can try somethign like..
    <!--$myHTMlMarkup =wcmElement("regexText")-->
    <!--$startindex= strIndexOf(myHTMlMarkup,"&gt;p&lt;")-->
    <$loopwhile startindex+ 1 > 0$>
         <!--$stopIndex= strIndexOf(myHTMlMarkup,"&gt;/p&lt;")-->
         <!--$para = strSubstring(myHTMlMarkup,startindex + 9,stopIndex) -->
         <!--$myHTMlMarkup=strIndexOf(myHTMlMarkup,stopIndex + 10)-->
         <!--$startindex= strIndexOf(myHTMlMarkup,"&gt;p&lt;")-->
    <!--$endloop-->

  • RegEx and capturing groups

    hi.
    i'm trying to use the capturing groups to extract substrings.
    this is the data format: MTWTFSS@2005-03-19
    and this my regex: Pattern.compile("((\\p{Upper}|-){7})@(19|20)\\d\\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])");
    i want to extract the substring before the @. i have set the capturing group, but i always get an error:
    java.lang.IllegalStateException: No match found
    at java.util.regex.Matcher.group(Matcher.java:353)
    at vdrremotecontrol.VDRTimer.(VDRTimer.java:93)
    at vdrremotecontrol.VDRRemoteControl.getTimersFromVDR(VDRRemoteControl.java:628)
    at vdrremotecontrol.VDRRemoteControl.loadSettings(VDRRemoteControl.java:855)
    at tvbrowser.core.plugin.JavaPluginProxy.doLoadSettings(JavaPluginProxy.java:191)
    ... 5 more
    what's the right way to set the capturing group?
    greetings, henrik

    me again :-)
    // MTWTFSS@2005-03-19
    Pattern repeatingAt =
    tingAt =
    Pattern.compile("((\\p{Upper}|-){7})@(19|20)\\d\\d-(0[
    1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])");
    if(dayPattern.matcher(day).matches()) {
    repeating = false;
    this.day_of_month = Integer.parseInt(day);
    } else if(datePattern.matcher(day).matches())
    tches()) {
    repeating = false;
    this.day_of_month =
    of_month =
    Integer.parseInt(datePattern.matcher(day).group(3));
    } else
    } else if(simpleRepeating.matcher(day).matches()) {
    repeating = true;
    repeating_days = determineDays(day);
    } else
    } else if(repeatingAtShort.matcher(day).matches())
    repeating = true;
    String days = day.substring(0,
    bstring(0, day.indexOf("@"));
    repeating_days = determineDays(days);
    } else if(repeatingAt.matcher(day).matches())
    tches()) {
    repeating = true;
    Matcher matcher =
    matcher = repeatingAt.matcher(day);
    System.out.println("#"+day+"#");
    System.out.println(matcher.groupCount());
    System.out.println(matcher.group(1));
    String days = day.substring(0,
    bstring(0, day.indexOf("@"));
    repeating_days = determineDays(days);
    }output is:
    [java] #MDMDFSS@2005-06-10#
    [java] 5
    [java] SCHWERWIEGEND: Die Einstellungen des
    n des Plugins "Video Disc Recorder" konnten nicht
    geladen werden.
    [java]
    java]
    (/home/henni/.tvbrowser/java.vdrremotecontrol.VDRRemot
    eControl.prop)
    [java] util.exc.TvBrowserException: Die
    : Die Einstellungen des Plugins "Video Disc Recorder"
    konnten nicht geladen werden.
    [java]
    java]
    (/home/henni/.tvbrowser/java.vdrremotecontrol.VDRRemot
    eControl.prop)
    [java] at
    a] at
    tvbrowser.core.plugin.JavaPluginProxy.doLoadSettings(J
    avaPluginProxy.java:197)
    [java] at
    a] at
    tvbrowser.core.plugin.AbstractPluginProxy.loadSettings
    (AbstractPluginProxy.java:114)
    [java] at
    a] at
    tvbrowser.core.plugin.PluginProxyManager.activatePlugi
    n(PluginProxyManager.java:505)
    [java] at
    a] at
    tvbrowser.core.plugin.PluginProxyManager.activateAllPl
    uginsExcept(PluginProxyManager.java:459)
    [java] at
    a] at
    tvbrowser.core.plugin.PluginProxyManager.init(PluginPr
    oxyManager.java:220)
    [java] at
    a] at tvbrowser.TVBrowser.main(TVBrowser.java:307)
    [java] Caused by:
    d by: java.lang.IllegalStateException: No match
    found
    [java] at
    a] at
    java.util.regex.Matcher.group(Matcher.java:353)
    [java] at
    a] at
    vdrremotecontrol.VDRTimer.<init>(VDRTimer.java:94)
    [java] at
    a] at
    vdrremotecontrol.VDRRemoteControl.getTimersFromVDR(VDR
    RemoteControl.java:628)
    [java] at
    a] at
    vdrremotecontrol.VDRRemoteControl.loadSettings(VDRRemo
    teControl.java:855)
    [java] at
    a] at
    tvbrowser.core.plugin.JavaPluginProxy.doLoadSettings(
    JavaPluginProxy.java:191)
    [java] ... 5
    ... 5
    more[/cod
    e][u][/u]
    This example executes fine.
            String expression = "((\\p{Upper}|-){7})@(19|20)\\d\\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])";
            String data = "MTWTFSS@2005-03-19";
            Pattern p = Pattern.compile(expression);
            Matcher m = p.matcher(data);
            while (m.find()) {
                System.out.println(m.group(1));
            }        /Kaj

  • Question on regex Matcher (group number)

    HI, everybody
    I am writing a program on replacement like the one below.
    String regex = "(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)";
    String original = "ABCDEFGHIJKL";
    String replacement = "$12";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(original);
    String result = m.replaceFirst(replacement);What I actually want is to take out the first group, in this case an "A", and append a character "2" after it.
    The result I am expecting is "A2". But the result I get is "L". For the regex engine takes it as the 12th group.
    What should I do to remove the ambiguity.
    Thanks.

    In such case, use $1\\2.

  • Reg Exp and non capturing groups

    Hello,
    I got problems with the non capturing groups in java.
    I want to extract the 2nd ocurenc of a given patern from a string.
    This ist the string =" 12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text"
    Now I want to extract the 2nd occurecy of the brackets with an unknow text pattern.
    I tried this pattern = "(?:\[\w+\] )\[w+\]"
    I thought that the non-capturing pattern helps me to find the first pair of [] brackets. the capturing group should give me want i want.
    But I still get the result: [Logging] [Success]"
    Even if I try just to use only the non cpaturing patern "(?:\[\w+\])" I still get an output from Matcher.group() which I didnt expect here!
    What I am doing wrong?
    Thanx for any help

    Sorry, sabre150 I just missed it to answer you.
    I have placed it into eclipse in a scrapbookpage into the following code:
    final String regexp = "[^\\]]*\\[[^\\]]*\\]\\s*(.*)";
    final String zeile = " 12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text";
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexp);
    java.util.regex.Matcher matcher = pattern.matcher("");
    matcher.reset(zeile);
    System.out.println("Found: "+matcher.find());
    System.out.println(matcher.group());Output was:
    Found: true
    12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text
    and not what I wanted
    "[Success] ### More text [Perhaps ...."
    I dont know what I am doing wrong.
    I thought I could solve it with the non-capturing group, but they doesnt seem to work.
    My question to the non-capturing group is:
    I have this pattern [code]"(?:.*)".
    This pattern will probably match the String "Hello Mary!"
    But it should not capture the string.
    So matcher.find() is true, but matcher.group() is the whole string and nit null, like I expected.

  • Util.regex matcher.groupCount()

    Hello all. I am trying to parse some text using regex. What I am parsing may have 1 or more matches per line and I need access to each match independantly. The code shown below works well in finding all matches except for the m.groupCount() always returns 0. Thus I can't to anything with individual matches. How can get the groupCount() to function properly?
    Thanks in advance.
    f (currentLine.startsWith("LOCUSLINK")){
                      line++;
                      String pattern = "[0-9]+";
                      Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
                      Matcher m = p.matcher(currentLine);
                      while(m.find()) {
                        int count = m.groupCount();
                        for (int x = 0; x <= m.groupCount(); x++)
                        System.out.println(line+"="+x+"="+count);

    There aren't capturing groups and really don't need to use in this case.
    Try this simple way:
    String re = "\\d+";
    Matcher m = Pattern.compile(re).matcher(anyString);
    for (int j=1; m.find(); j++) {
    System.out.println("matching " + j + ": " + m.group(0));
    ..

  • 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).

  • Encountering error End tag does not match start tag 'group'

    Hi guys,
    am a newbee to XML Publisher.
    I am encountering the below error:
    Creating XDO Report at: Wed May 25 16:38:14 GMT+05:30 2011
         sql = select 'TEST' from dual;
         description = Learning XML Reporting
         port = 1561
         user = apps
         host = e2dscorhrmdba01.cendant.com
         sid = ABGHRDEV
         ReportParameters = {}
         path = D:\lanosrep\XML\Output\FirstXMLReport
         data_source_name = ABGHRDEV
         name = FirstXMLReport
    oracle.xml.parser.v2.XMLParseException: End tag does not match start tag 'group'.
         at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:205)
         at oracle.xml.parser.v2.XMLReader.popXMLReader(XMLReader.java:516)
         at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1242)
         at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:301)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:268)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:227)
         at oracle.apps.xdo.dataengine.DataProcessor.getSQLSchema(DataProcessor.java:528)
         at oracle.apps.xdo.dataengine.DataProcessor.writeXMLSchema(DataProcessor.java:476)
         at CreateXDOReport.createXDOReport(CreateXDOReport.java:164)
         at CreateXDOReport.process(CreateXDOReport.java:108)
         at CreateXDOReport.main(CreateXDOReport.java:298)
    I have tried reinstalling the patch but of no use.
    Please guide me.

    I changed the sql query
    select 'TEST' from dual;
    to select 'TEST' from dual
    It is working fine now :)

  • SQL CASE statement in XML template- End tag does not match start tag 'group

    Hi All,
    I am developing a report that has the SQL CASE statement in the query. I am trying to load this into RTF with report wizard and it gives me below error
    oracle.xml.parser.v2.XMLParseException: End tag does not match start tag 'group'
    Does XML publisher support CASE statement?
    My query is something like this
    SELECT customercode,
    SUM(CASE WHEN invoicedate >= current date - 30 days
    THEN balanceforward ELSE 0 END) AS "0-30",
    SUM(CASE WHEN invoicedate BETWEEN current date - 60 days
    AND current date - 31 days
    THEN balanceforward ELSE 0 END) AS "31-60",
    SUM(CASE WHEN invoicedate < current date - 60 days
    THEN balanceforward ELSE 0 END) AS "61>",
    SUM(balanceforward) AS total_outstanding
    FROM MyTable
    GROUP BY customercode
    ORDER BY total_outstanding DESC
    Please advice if the CASE statement or the double quotes are causing this error
    Thanks,
    PP

    I got this to work in the XML but the data is returning zeros for all the case statements. When I run this in toad I get results for all the case conditions but when ran in XML the data displayed is all zeros. I am not sure what I am missing. Can someone shed some light on this please
    Thanks!
    PP

  • Regex matching bug?

    it seems like j2sdk1.4.2b has some serious regex matching bug with strings that contain unicode characters. In my case, the string contained some Turkish chars.
    regex is simple <[^>]*> which matches string runs that are enclosed in <>
    (ex. <field>)
    although the matching is successful with j2sdk1.4.1_02, it just doesn't match unicode containing text with 1.4.2b
    What do you think? Is this a bug or could I be missing something?

    ahmeti, did you submit a bug report on this? Because it definitely is a bug in the Pattern class, I finally figured out. They added a new node type to make matching ASCII characters in character classes more efficient, but they screwed up the match condition: it always returns false if the character it's looking at is not ASCII, even if the class has been negated. I'll go ahead submit a report myself unless I hear from you.

  • [bug]Jdev 11g:NullPointerException at java.util.regex.Matcher.getTextLength

    Hi,
    Jdev 11.1.1.0.31.51.56
    If somebody of you get the following trace stack when running a jspx using ViewCriteriaRow.setOperator :
    There is bug 7534359 and metalink note 747353.1 available.
    java.lang.NullPointerException
    at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
    at java.util.regex.Matcher.reset(Matcher.java:291)
    at java.util.regex.Matcher.<init>(Matcher.java:211)
    at java.util.regex.Pattern.matcher(Pattern.java:888)
    at oracle.adfinternal.view.faces.model.binding.FacesCtrlSearchBinding._loadFilter
    CriteriaValues(FacesCtrlSearchBinding.java:3695)
    Truncated. see log file for complete stacktrace
    Workaround:
    If you use 
            vcr.setAttribute("Job",job);
    or
            vcr.setAttribute("Job","="+job);
    than add following line of code:
            vcr.setOperator("Job","=");   regards
    Peter

    Hi,
    useful to mention that this happens when setting the equal operator or LIKE operator
    vcr.setAttribute("Job","= '"+job+"'");
    or
    vcr.setOperator("Job","=");
    Frank

  • Regex Matching Involving Unicode

    Hi,
    I'm trying to do a regex match using boost::regex and followed the instructions on http://niemannross.com/developer/wiki/index.php?title=Using_boost_regular_expressions_(re gexp)_in_InDesign_CS/CS2/CS3_plug-in_code
    My regex needs to match a line that ends with punctuation characters and return the string that excluding the ending punctuation characters.
    ex. home -> home
    ex regex: (.*?)[ \\x{201C}\\x{201D}]+$
    however it does not match the line.
    I tried using boost::u32regex but i'm getting a boost::icu_regex_traits::translate_nocase symbols not found error on linking.
    How can I go around this problem?
    Thanks in advance!
    -- Jeff

    Escaping the backslash in '\x' is necessary for your programming language, otherwise it is interpreted as a 'real' hex character. So as it is, this feeds '\x{201C]' into your program, rather than the literal 0x201C code. (It'd be a syntax error for C, but you get the point.)
    However: because this is an expression IN GREP inside your running program, I think you have to escape it again, so it might need double double backslashes. Scripts suffer the same problem.

  • Making Presets - After Effects error: internal verification failure, sorry! {unexpected match name in group} (29 :: 0)

    I am attempting at making a preset for myself, because I want to speed up the time it takes to make and add effects to layers.
    I began by using an online generator to generate my preset shell (the outline of the preset). I then took the code it gave me, and
    pasted it into my PresetEffects.xml (C:\Program Files\Adobe\After Effects CC 2014\Support Files\PresetEffects.xml) and when I went
    into After effects CC, I opened up the script editor (File>Scripts>Open Script Editor), then I pasted my import java code:
    app.project.activeItem.layer(1).effect.addProperty("Audio_Waveform_Wheel");
    When I press the "Run" button, something happens, then on my after effects a pop up message comes up saying:
    After Effects error: internal verification failure, sorry! {unexpected match name in group} (29 :: 0)
    When I press OK, it just opens up again. My software also looks a little messed up. What is going on?
    How do I fix this issue?

    The After Effects CC 2014.1.1 (13.1.1) update fixes several bugs, including this one. Let us know how it's working for you once you've installed the update.
    Details: http://bit.ly/AE_1311_details

  • Regular expressions question - making a capture group optional to match.

    Hello java Experts...
    I have a problem with making a group optional to match. I am using a pattern to match a text from an apache/bittorrent log. This text sometimes contains an IP address and sometimes it doesn't. Here is an example:
    GET /announce?info_hash=E%E9%C6%1D%DC%7EA%CD%EB%97%C8%85%DC%26M4%DB%11%18%1D&peer_id=%00%00%00%00%00%00%00%00%00%00%00%005%86%07%1An%F0%8E/&port=6882&ip=130.233.20.169&uploaded=0&downloaded=0&left=1855094951&event=started HTTP/1.0I used this pattern to parse it and it works:
    (\\w+\\s\\/\\w+)\\?(info_hash)\\=([\\d\\w\\%\\/]+)\\&(peer_id)\\=([\\d\\w\\%\\/]+)&(port)\\=(\\d+)\\&(ip)*\\=([\\d.]+)*\\&(uploaded)\\=(\\d+)\\&(downloaded)\\=(\\d+)\\&(left)\\=(\\d+)\\&(event)\\=(\\w+)";Now if the IP address is not in the log entry, the above pattern won't match. For example, this text doesn't match against the pattern:
    GET /announce?info_hash=E%e9%c6%1d%dc%7eA%cd%eb%97%c8%85%dc%26M4%db%11%18%1d&peer_id=%d6%be%9f%88%28C5%eb%1c%cdI%98j%c5H%80%5d%3bJ%99&uploaded=0&downloaded=0&left=1855094951&event=started HTTP/1.0So what I am trying to tell the regex engine is that some entries contain an IP address, so take it then into a group, but if some entries don't, then don't bother with it. How do I go about doing that?
    Any help would be greatly appreciated and thanks for your time :)

    I tried it, but apparently it doesn't work. I guess java somehow numbers groups differently when they're nested. I thought doing
    (ip)?\\=([\\d.]+)? would make it optional to match the IP part of the log entry, but it doesn't.
    Also tried nesting them in one: (\\&(ip)\\=([\\d.]+))? which is just the same as you proposed, but it still gives the No Match Found exception.

Maybe you are looking for

  • HDV image quality problems on capture

    Hey gang! I just got my first tape shot on a Sony Z1U, and I'm trying to caputre with the M10U deck. My problem is that the footage looks fine in the camera, and looks the same when played from the deck (via component video) to two different monitors

  • Installing Yosemite failed om 2012 Mac PRO

    I have tried to install Yosemite on my Mac PRO (OS X 10.9.5) It looked good in the beginning but turned out to be a total disaster. I couldn't start my computer again. I tried it again but it failed again! Now I put OSX 10.9.5 back on again and lucki

  • Media manager crashes - across - disks

    I was trying to use media manager in FCP (latest version) to copy (and delete excess) a project. I was doing so from one LaCie firewire disk to another. I kept getting kernels. Tried as much debugging as possible without luck. Finally tried by doing

  • Http header setting in servlet

    Hello, I want to set the header parameters of http response in my servlet. I set parameters as below:           theResponse.setHeader("Request Version", "HTTP/1.1");           theResponse.setStatus(200);           theResponse.setHeader("Date", "Wed,

  • Security FAIL safari 0S 10.8 Mountain Lion ALERT

    Best Regards I have upgraded to 10.8. I logged into one of my secure sites, paypal. I noticed there is NO INDICATOR usually you see in the upper right a closed padlock to show you are securely logged in. Did not see this or anything at all to indicat