How to get the offset by using the name-capture-group in Java 7?

Hi all

Java 7 provides the capturing group named in the Regex Matcher class, but it lacks several methods that returns the offset associated with the named capturing group. At least, the following two methods:

(1) int end (String name);
Returns the offset after the last character in the subsequence captured by the named capturing group during the previous match operation.
(2) int start (String name);
Returns the starting index of the subsequence captured by the named capturing group during the previous match operation.

Given that these two methods do not exist in the Java 7 courses, the second line of printing in the following example does not work. Someone suggested to make it work?

String matching = "aaabbbaaa";
String pattern = "(?) (< AString > a +) b * a * "; "AString" is a named capturing group
Patten pattern = Pattern.compile (pattern);
Matcher Matcher = patten.matcher (match);
int groupID = 1; In this example, we know that the "AString" a group ID = 1, but most of the time, we do not know the ID of Group of the named capture group.

If (matcher.matches ()) {}

When you know the ID of the group, it is easy to use.
System.out.println ("found the text-" "+ matcher.group (groupID) +" \"nerd index" +)
Matcher.Start (GroupId) + "and end at index" + matcher.end (groupID));

The following line does not work
System.out.println ("found the text-" "+ matcher.group ("AString") +" \"nerd index" +)
Matcher.Start("aString") + "and end at index" + matcher.end ("AString"));

}

Thank you very much.

Tao

taoqian wrote: anyone got the suggestion to make it work?

I'm at a loss as to what you expect members of this forum to do. The Matcher class does not have the two methods you want and you already have a workaround that you can use the id of group digital. Now you could trigger a bug report, suggesting a change, but at best, this is likely to take years to implement.

Although I don't really see no advantage and seems to go against the spirit of the use of group names, if you absolutely need to use the name of a group, then you might create a mapping between a group and its index name.

Tags: Java

Similar Questions

  • How to get the name of sbRIO programmatically

    How to get the 'name' and 'Comment' by sbRIO I write to sbRIO-9602 Max in the box of Identification (model, serial number, MAC address, name)?

    Use RT Information.vi of target is located under the range of public services under LabVIEW Realtime.

    Christian

  • How to get the name of the particular index table option.

    Hello

    Can any body tell how to get the name of the item to a particular array.i have a table within array.i must compare the name of Francesca in particular key.here is the table.

    myArray= Array (@43b1e09)
    [0] = object (@42b33f9)
    Testing_1 = Array (@4428821)
    [0] = object (@43adc19)
    choice_id = '0 '.
    delete = "N".
    DownloadURL = "xyz".
    selected = 'Y '.
    translation = "2_486."
    length = 1
    length = "N".
    Editable = 'Y '.
    field_id = '388 '.
    LanguageLink = 'Y '.
    linked_definition_id = null
    multiple values = "N".
    name = "Photo".
    otheroption = "N".
    photovitlink = object (@43ad0d9)
    required = "N".
    step = '1 '.
    translation = "Photo".
    visible = 'Y '.
    [1] = object (@43ad5d9)
    [2] = object (@4490089)

    Here is the structure of the table I get server side.i give table name of result as table myArray.This have several child as an object of object.each having .i table (Testing_1 in the first case) must get the name of this Testing_1 table and compare with my sort key that I perform an operation. But I am unable to get the name of this Testing_1 array(Since_it_is_dynamic_so_this_name_changes_some_times).can a body guide me how to get the name of this table.



    Thanks and greetings

    Vineet Sharma

    Hi Vineet Osho,

    You can browse your object using the loop and you can get the name of the table... as below...

    for each (var obj:Object in myArray)
    {
    for (var str:String in obj)
    {
    If (obj [str] is array)
    {
    var arrayName:String = str;
    }
    }
    }

    Thank you

    Jean Claude

  • How to get the name of the server instance

    Hi all!!

    First of all, sorry if this is not the place to leave this question, but I didn't know where to post.

    I have a weblogic 9.2 MP3 installed in a x 64 Redhat Linux. It is clustered in 2 cases.
    An application is deployed in both cases, each request between two instances of balancing.

    Of course, a request is responsed by only one instance, and I would like to know how to get the name of the instance that processes a request of some.

    I read that I can send using recorded weblogic mbeans in this way:
    InitialContext ctx = new InitialContext();
    MBeanServer mbean = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
    Then
    ObjectName rs = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
    Set beans = mbean.queryNames(rs, null);
    And finally I iterate over the beans, but I'm not able to retrieve the name of the instance. I suppose that the object name is not appropriate.

    However, I am able to get the name of the server and the two names of instances per a JMX connection to service:jmx:t3://localhost:7001/jndi/weblogic.management.mbeanservers.domainruntime, but this isn't what I want because I need to know what is the instance that is a certain demand.

    Anyone know how I can do?

    Thank you very much and sorry for the English xD

    Published by: mamntc02 on 01/05/2010 05:10

    That should do it...

    private String getServerName() throws Exception {}
    try {}
    Context ctx = new world;
    MBeanServer mbeanServer = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");

    String runtimeServiceName = "com.bea:Name = RuntimeService, Type = weblogic.management.mbeanservers.runtime.RuntimeServiceMBean;

    Create ObjectName for the runtime
    RuntimeService ObjectName = new ObjectName (runtimeServiceName);

    Get the object for the ObjectName ServerRuntimeMBean name
    ObjectName serverRuntime = mbeanServer.getAttribute (runtimeService, "ServerRuntime") (ObjectName);

    Get the name of the server
    String serverName = (String) mbeanServer.getAttribute (serverRuntime, "Name");
    If (serverName == null) return "";
    otherwise return serverName;
    }
    catch (Exception e) {}
    throw e;
    }
    }

  • How to get the names of the table columns in the quick dashboard

    How to get the names of the table columns in the quick dashboard


    Thanks and greetings
    ------------------------
    Kishore P

    Make a prompt like:

    SELECT case when 1 = 0 then 'D0 time. " "" T02 by month name "other" 'D2 market' '. "" M04 region' ' the end 'Sample Sales' UNION ALL SELECT case when 1 = 0 then 'D0 Time. " "" T02 by month name ' else ' 'Time D0. "" T02 by month name ' ' the end 'Sample Sales.

    Put the name of column in single quotes.

    Make your rank as a function:
    Rank ('F1 income'. "" Recipes 1-01 (after all) "by @{pColumn} {'D0 time'. ({"" T05 annually name '})

    It works fine for me

    concerning

    John

    http://obiee101.blogspot.com

  • How to get the names of the tabs in the void?

    Hi all

    Could someone tell me how to get the names of all the tabs of void?

    I have Parent tab T1. T1 has 3 tabs sup T1_1, T1_2 and T1_3.

    I would like to have T1_1, T1_2 and T1_3 names tab in the list.

    Thanks in advance!

    Dip

    Dip,

    You can get the name of the tab of the apex, apex_application_tabs & apex_application_parent_tabs dictionary views. Thank you.

    Kind regards
    Manish

  • How to get the name of a class private data controls?

    How can I get the names of the controls within a class private data?

    I use the framework of the actor and try to create a tha method will be executed when run the actor. This method should an o list all names of control inside the data class to find the initial value within a configuration file (config.ini file), the key to the configuration file will be the name of the control.

    Thank you.

    You already do the substitution method just because you write for the bundle by name.  And then how are you going to respond to all types of data might be the key.  You do more difficult things that it takes to really very few benefits.

  • How to get the name of the albums

    How can I get the name of albums and the is photo exist in each albums...

    Yes, and you can copy it to your device by using the Momentics IDE (view information, target file system browser) and then open it in a tool of SQLite. There is a table called 'albums' which contains the tracks from the album.

    A word of warning if you go to this approach. We reserve the right to change the database schema. This isn't a public API, it's a work-around that may or may not be suitable for your application.

    Porting a library may be the best choice for you.

  • How to get the name and number of the procedure parameter list or a function?

    I stated the procedure described in the package

    If I want to get the number and the name of the parameter list, so how do I it

    I don't have I her name with the package.

    create or replace package demoApp is

    PROCEDURE insert_data (p_fname IN VARCHAR2,

    p_lname IN VARCHAR2,

    p_address IN VARCHAR2,

    p_cellno IN VARCHAR2,

    p_email IN varchar2);

    end demoApp;

    create or replace package demoApp body is

    PROCEDURE insert_data (p_fname IN VARCHAR2,

    p_lname IN VARCHAR2,

    p_address IN VARCHAR2,

    p_cellno IN VARCHAR2,

    p_email IN varchar2) IS

    EmpID number;

    BEGIN

    Select nvl (max (emp1.empid), 0) + 1 in EMP1 empid;

    INSERT INTO VALUES EMP1 (empid, p_fname, p_lname, p_address, p_cellno, p_email);

    EXCEPTION

    WHILE OTHERS THEN

    raise_application_error (-20001,' insert the problem ' |) SQLERRM);

    END;

    end demoApp;

    -----------------

    I want to get the name of the parameter and the number of use of stroredrprocedure ""demoApp.insert_data " "

    Select *.

    of all_arguments

    where package_name = 'DEMOAPP.

    and object_name = 'INSERT_DATA.

  • How to get the name of the client computer and the name of the customer osuser

    Hello everyone,
    the trigger below works fine. But I want to get the name of the client computer and the name of osuser customer in the output of the same trigger shown below, how do I do this in the same trigger? any help is highly appreciated.
    Thank you and best regards.

    triggering factor:
    ------------
    CREATE TABLE logonaudit
    (
    user_id VARCHAR2 (30),
    sess_id NUMBER (10),
    LOGON_TIME DATE,
    host VARCHAR2 (20));

    Table created.

    CREATE OR REPLACE
    Logon_audit RELAXATION
    AFTER LOGON
    WE DATABASE
    DECLARE
    V_program varchar2 (120);
    BEGIN
    SELECT UPPER (program)
    IN v_program
    SESSION $ v
    WHERE audsid = sys_context ('USERENV', 'SESSIONID');
    If (upper (v_program) as 'TOAD %' or upper (v_program) like '% SQLPLUS %')
    then
    INSERT
    IN logonaudit
    VALUES)
    user,
    sys_context ('userenv', 'sessionid'),
    SYSDATE,
    sys_context ('userenv', 'host')
    );
    end if;
    END;

    the output showing sessionid, date, db user name, as a local server machine name.but I want osuser of customer names and the name of the client computer as you know connection of clients to the database of their machines.how can I achieve? any help much appreciated.

    Published by: 938946 on December 25, 2012 12:15 AM

    According to AskTom - do not use audsid, dangerous - can be 'zero '.

  • How to get the name of the current PDF file?

    Hello world

    I know this is maybe a question has been asked millions of times, but I couldn't find a straight answer.

    I am using a workflow that comes with a Content Manager Solution is not Adobe this WF will generate a file very long (about 30 characters) name that will be used as the number of unique processes.

    To go to the step next in the workflow that I have to update the table in the database and registration update will use the process number.  What I did is that I added a field in hidden text in the form, which should have the number of processes on the initialize function.

    Now my question is how to get the file name of the opened PDF file?

    I'm sure that there is a function in JS, but I couldn't find the way to do it.

    Thanks in advance guys for help.

    Mazen

    Acrobat can create LiveCycle Design possible forms, but each uses a different and different languages or syntax approach.

    There are a number of ways to get the file name and path, urt getFileName.

  • How to get the name constraintlist and column in a table?

    Hello


    can someone please tell me how to get the type of constraint, and it is imposed on the names of columns in a table.




    Thank you
    Nico

    Hello

    Use the two tables:

    select * from all_constraints
    
    select * from ALL_CONS_COLUMNS
    

    Sorry SY, you were faster than me...

    Published by: user11268895 on August 19, 2010 13:27

  • How to get the name of the node?

    Hi guys,.

    I have a path that looks like this 1stLevel/root/dynamicLevel

    How can I get the name of the node in dynamic level when it come with different node name so that I can catch it in a variable?

    This can change according to the author of the application

    root/1stLevel/dynamicLevel1
    root/1stLevel/dynamicLevel2
    root/1stLevel/dynamicLevel3
    root/1stLevel/dynamicLevel4

    What software? In OSB try Assign with this expression:

    fn:name($body/root/firstLevel/*[1])
    

    In addition, you cannot use element named "1stLevel" because it starts with number.

  • How to get the name of the element when running from popup menue?

    Hello

    I am using the 10.2 forms and a form with 2 listitems (mouse and keyboard navigable = No./false) with the same popup menu.
    When I'm currently running then menu-trigger point: system.mouse_item is not defined and: system.cursor_item the value von hase something else.

    How to get the itemname of the element that is currently leading the context menu?

    Robert

    Hello!
    Can create a PRE-POPUP-MENU trigger on block level
    with a call to go_item (: system.mouse_item)
    You know, you're on what item in the list when the context menu is active.
    Concerning

  • How to get the name of the bluetooth device and the name of the bluetooth device address device class?

    Hi all

    Can I know how to get the bluetooth device name and the name of the bluetooth device address device class?

    Example:-if my bluetooth device address is :-98:EB:CD:01:1F::90 then how do I get my bluetooth device name?

    I hope you understand my problem. Let me know as soon as possible.

    :

    Thanks for the reply.

Maybe you are looking for

  • Call forwarding does not work ;-((

    Hello I got Skypenumbers from the beginning. But since two months call forwarding no longer works. I renewed my subscription; I have 30 euros on credit account. I even tried a new Skype number to see if the old number could have crashed. But also the

  • Strange black rectangle top-right

    I have a strange black rectangle in the upper right corner of the office. It is above all the windows, which means that I can't use the close button, and it contains two or three numbers. Usually, they are 060 001, but sometimes it turns into 058 001

  • 900 Yoga - what is the small button next to the Jack headphones?

    Hello. I do not speak for the power button, but the smaller button between the power button and the headphone input. And while we're at it, what is the tiny indentation just beside the power button which looks like this could be a reset of a certain

  • The use of data in the dialog box

    Hello I started using DIAdem Dialog Editor and I wonder how I would use data that has been entered in a dialog box or table cell perform some calculations on it and display the results in another dialog box. I'd also be looking to retrieve data in a

  • Contact Windows, double contacts.

    Member - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: You have problems with programs Error messages Recent changes to your computer What you have already tried to solve the problem