Regex to exclude a literal substring

I am trying to match a set of strings using a regular expression, but I also want to exclude several literals.
For example, I want to match all strings starting with root_obj.item_type., except those that end in the literal string emitter.
To match is simple enough ... the pattern I would use would be "root_obj\\.item_type\\..*". However, this would match strings ending with "emitter". I have tried a negative zero width lookahead (though I am uncertain exactly what that means), "root_obj\\.item_type\\..*(?!emitter)", but this still matches the strings I am attempting to exclude.
I have looked on the web, but have not found an answer to this. Any suggestions?
� {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

jverd wrote:
sharkura wrote:
I guess you are saying only match strings that have exactly zero instances of emitter at the end of the string.
I also thought of
str.matches( "root_obj\\.item_type\\..*[^e][^m][^m][^i][^t][^t][^e][^r]" ); but I didn't even test it because it looks so ugly.It's also incorrect.
You're saying after item_type.*, it has to have exactly 8 characters, and the first can't be e, and the second and third can't be m, fourth can't be i, etc.Ah, so, desu ka.
I tried cotton's first solution, and it still matches the strings to reject. I am going to go beat my head against a book or a google until I figure this out. Thanks for the help, peoples.
� {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • RegEx to find "T-" literally

    I've been trying to find some help on writing regular
    expressions and haven't been very lucky. I'm trying to write a
    regular expression to find "T-" to use with REFind.
    Would the RegEx be \T- ?

    You don't need to (and shouldn't) use a regex to find a
    literal; just use
    find().
    Adam

  • Regex - matching literal characters

    Im trying to match the following pattern using regex:
    The string begins with a literal '\' is followed by any number of letters and/or numbers and ends with '&0]'
    e.g. '\07761739009B&0]'
    Im trying to devise my pattern but Im not exactly sure how to work with matching literal characters, I was lead to believe a '//' would dictate that the character is literal but this doesnt work:
    Pattern Serial = Pattern.compile("(\\/.*+\\&0])");Thanks in advance for any advice

    \ is an escape character both in Java string literals and in regex.
    "\\" produces a String containing a single \ character. But for a literal \, regex needs \\. So "\\\\" produces a single string containing \\ which in regex becomes a single literal \.
    Also, I don't think you need to escape &. And you might need to escape ] but I'm not sure--it might be okay bare if there was no preceding [.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Regex issue

    I am trying to figure out regex to exclude particular word match .
    Like regex should match all other A-Z chars combination except the word "Default" .
    How do i do that ?
    Please suggest solution on this

    Case 1 :String before
    String str = "<tuv xml:lang="Default" changedate="1900-01-01T12:00:00.000000">";
    str = str.replaceAll("REGEX","newValue");String After replace would be (No Change)
    String str = "<tuv xml:lang="Default" changedate="1900-01-01T12:00:00.000000">";Case 2 :String before
    String str = "<tuv xml:lang="ChangeMe" changedate="1900-01-01T12:00:00.000000">";
    str = str.replaceAll("REGEX","newValue");String After replace would be (Changed String)
    String str = "<tuv xml:lang="newValue" changedate="1900-01-01T12:00:00.000000">";

  • Return regex string

    I know how to run an regular expression and return a boolean if the pattern is matched.
    How do I return the actual string that is matched?
    e,g The is string is:
    "fasfasf safas 12345 rgrg"
    My regex matches 12345
    I want to return 12345 as a string rather than a boolean stating the match was sucesfull.
    Thanks

    jk987 wrote:
    I know how to run an regular expression and return a boolean if the pattern is matched.
    How do I return the actual string that is matched?
    e,g The is string is:
    "fasfasf safas 12345 rgrg"
    My regex matches 12345
    I want to return 12345 as a string rather than a boolean stating the match was sucesfull.
    ThanksIf your 'regex' is always a literal string, you could use String.indexOf() method. If not, try
    public class Jk987{
      public static void main(String[] args){
        String s1 = "fasfasf safas 12345 rgrg";
        String s2 = "fasfasf safas rgrg";
        String regex = ".*(12345).*";
        String res1 = s1.replaceFirst(regex, "$1");
        String res2 = s2.replaceFirst(regex, "$1");
        System.out.println(res1);
        System.out.println(res2);
    }

  • Question about bluetooth communication between PC and mobile device

    I am a newbie of bluetooth communication. This time I need to have connumication between PC and mobile device (mainly mobile phone) by sending strings. PC is acted as server and mobile device act as client.
    For using bluetooth in PC, I use bluecove 2.0.1
    I have already connected them successfully.
    When I want to send strings between them, it is found that it can only do one cycle of communication (client -> server -> client).
    For my design, they can communicate multiple times.
    I simulate the core class of the system, the performance is fine.
    Cound anyone help me to watch the code and give me some advices?
    Server Side - ServerBox.java
    public class ServerBox implements Runnable {
       LocalDevice localDevice;
       StreamConnectionNotifier notifier;
       ServiceRecord record;
       boolean isClosed;
       ClientProcessor processor;
       CMDProcessor cmd;
       MainInterface midlet;
       private static final UUID ECHO_SERVER_UUID = new UUID(
               "F0E0D0C0B0A000908070605040302010", false);
       public ServerBox(MainInterface midlet) {
           this.midlet = midlet;
       public void run() {
           boolean isBTReady = false;
           try {
               localDevice = LocalDevice.getLocalDevice();
               if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC)) {
                   midlet.showInfo("Cannot set to discoverable");
                   return;
               // prepare a URL to create a notifier
               StringBuffer url = new StringBuffer("btspp://");
               url.append("localhost").append(':');
               url.append(ECHO_SERVER_UUID.toString());
               url.append(";name=Echo Server");
               url.append(";authorize=false");
               // create notifier now
               notifier = (StreamConnectionNotifier) Connector.open(url.toString());
               record = localDevice.getRecord(notifier);
               isBTReady = true;
           } catch (Exception e) {
               e.printStackTrace();
           // nothing to do if no bluetooth available
           if (isBTReady) {
               midlet.showInfo("Initalization complete. Waiting for connection");
               midlet.completeInitalization();
           } else {
               midlet.showInfo("Initalization fail. Exit.");
               return;
           // produce client processor
           processor = new ClientProcessor();
           cmd = new CMDProcessor();
           // start accepting connections then
           while (!isClosed) {
               StreamConnection conn = null;
               try {
                   conn = notifier.acceptAndOpen();
               } catch (IOException e) {
                   // wrong client or interrupted - continue anyway
                   continue;
               processor.addConnection(conn);
       // activate the set up of process
       public void publish() {
           isClosed = false;
           new Thread(this).start();
       // stop the service
       public void cancelService() {
           isClosed = true;
           midlet.showInfo("Service Terminate.");
           midlet.completeTermination();
       // inner private class for handling connection and activate connection handling
       private class ClientProcessor implements Runnable {
           private Thread processorThread;
           private Vector queue = new Vector();
           private boolean isOk = true;
           ClientProcessor() {
               processorThread = new Thread(this);
               processorThread.start();
           public void run() {
               while (!isClosed) {
                   synchronized (this) {
                       if (queue.size() == 0) {
                           try {
                               // wait for new client
                               wait();
                           } catch (InterruptedException e) { }
                   StreamConnection conn;
                   synchronized (this) {
                       if (isClosed) {
                           return;
                       conn = (StreamConnection) queue.firstElement();
                       queue.removeElementAt(0);
                       processConnection(conn);
           // add stream connection and notify the thread
           void addConnection(StreamConnection conn) {
               synchronized (this) {
                   queue.addElement(conn);
                   midlet.showInfo("A connection is added.");
                   notify();    // for wait() command in run()
       // receive string
       private String readInputString(StreamConnection conn) {
           String inputString = null;
           try {
               DataInputStream dis = conn.openDataInputStream();
               inputString = dis.readUTF();
               dis.close();
           } catch (Exception e) {
               e.printStackTrace();
           return inputString;
       private void sendOutputData(String outputData, StreamConnection conn) {
           try {
               DataOutputStream dos = conn.openDataOutputStream();
               dos.writeUTF(outputData);
               dos.close();
           } catch (IOException e) {
       // process connecion
       private void processConnection(StreamConnection conn) {
           String inputString = readInputString(conn);
           String outputString = cmd.reactionToCMD(inputString);
           sendOutputData(outputString, conn);
    /*       try {
               conn.close();
           } catch (IOException e) {}*/
           midlet.showInfo("Client input: " + inputString + ", successfully received.");
    }For "CMDProcessor" , it is the class of message processing before feedback to client.
    Client side - ClientBox.java
    public class ClientBox implements Runnable, CommandListener{
        StringItem result = new StringItem("","");
        private DiscoveryAgent discoveryAgent;
        private String connString;
        private boolean isClosed = false;
        private boolean boxReady = false;
        StreamConnection conn;
        private static final UUID ECHO_SERVER_UUID = new UUID( "F0E0D0C0B0A000908070605040302010", false);
        Form process = new Form("Process");
        ClientInterface midlet;
        public ClientBox(ClientInterface mid){
            this.midlet = mid;
            process.append(result);
            process.addCommand(new Command("Cancel",Command.CANCEL,1));
            process.setCommandListener(this);
            new Thread(this).start();
        public void commandAction(Command arg0, Displayable arg1) {    
            if(arg0.getCommandType()==Command.CANCEL){
                isClosed = true;
                midlet.notifyDestroyed();
        public synchronized void run() {
            LocalDevice localDevice = null;
            boolean isBTReady = false;
            /* Process Gauge screen */
            midlet.displayPage(process);
            Gauge g=new Gauge(null,false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING);
            process.append(g);
            showInfo("Initalization...");
            System.gc();
            try {
                localDevice = LocalDevice.getLocalDevice();
                discoveryAgent = localDevice.getDiscoveryAgent();
                isBTReady = true;
            } catch (Exception e) {
                e.printStackTrace();
            if (!isBTReady) {
                showInfo("Bluetooth is not avaliable. Please check the device.");
                return;
            if(!isClosed){
                try {
                    connString = discoveryAgent.selectService(ECHO_SERVER_UUID, ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
                } catch (BluetoothStateException ex) {
                    ex.printStackTrace();
            else return;
            if (connString == null) {
                showInfo("Cannot Find Server. Please check the device.");
                return;
            else showInfo("Can Find Server, stand by for request.");
            boxReady = true;
        /* True if the clientbox is ready */
        public boolean getBoxReady(){
            return boxReady;
        /* True if the clientbox is closed in run() */
        public boolean getIsClosed(){
            return isClosed;
        public String accessService(String input) {
            String output = null;
            try {
                /* Connect to server */
                StreamConnection conn = (StreamConnection) Connector.open(connString);
                /* send string */
                DataOutputStream dos = conn.openDataOutputStream();
                dos.writeUTF(input);
                dos.close();
                /* receive string */
                DataInputStream dis = conn.openDataInputStream();
                output = dis.readUTF();
                dis.close();
            } catch (IOException ex){
                showInfo("Fail connect to connect to server.");
            return output;
        private void showInfo(String s){
            StringBuffer sb=new StringBuffer(result.getText());
            if(sb.length()>0){ sb.append("\n"); }
            sb.append(s);
            result.setText(sb.toString());
    }Client side - ClientInterface.java
    public class ClientInterface extends MIDlet implements Runnable, CommandListener{
        private ClientBox cb = new ClientBox(this);
        private Form temp = new Form("Temp");
        private Command select = new Command("Select", Command.OK, 1);
        private Command back = new Command("Back", Command.BACK, 1);
        Alert alert;
        String[] element;
        String out;
        List list;
        public void run(){
            /* Send message and get reply */
            out = cb.accessService("Proglist");
            element = split(out,",");
            /* Use the reply to make list */
            list = createList(element[0], List.IMPLICIT, out);
            list.addCommand(select);
            list.addCommand(back);
            list.setCommandListener(this);
            Display.getDisplay(this).setCurrent(list);
        public void startApp() {
            System.gc();
            waitForBoxSetUp(); /* Recursively check for clientbox status */
            new Thread(this).start();
        public void pauseApp() {
        public void destroyApp(boolean unconditional) {
            notifyDestroyed();
        public void displayPage(Displayable d){
            Display.getDisplay(this).setCurrent(d);
        private void waitForBoxSetUp(){
            while(!cb.getBoxReady()){
                if(cb.getIsClosed())
                    notifyDestroyed();
        public void commandAction(Command c, Displayable d){
            if (c.getCommandType() == Command.OK){
                if (d == list){
                    /* Send the choice to server */
                    out = cb.accessService(list.getString(list.getSelectedIndex()));
                    alert = new Alert("Output", "selected = "+out, null, AlertType.ALARM);
                    alert.setTimeout(2000);
                    Display.getDisplay(this).setCurrent(alert,list);
            if (c.getCommandType() == Command.BACK){
                notifyDestroyed();
        public void showWarning(String title, String content){
            alert = new Alert("Output", "selected = "+list.getString(list.getSelectedIndex()), null, AlertType.ALARM);
            alert.setTimeout(3000);
            Display.getDisplay(this).setCurrent(alert,list);
        private List createList(String name, int type, String message){
            List temp;
            String[] source = split(message,",") ;
            temp = new List(name, type, source, null);
            return temp;
        private static String[] split(String original,String regex)
            int startIndex = 0;
            Vector v = new Vector();
            String[] str = null;
            int index = 0;
            startIndex = original.indexOf(regex);
            while(startIndex < original.length() && startIndex != -1)
                String temp = original.substring(index,startIndex);
                v.addElement(temp);
                index = startIndex + regex.length();
                startIndex = original.indexOf(regex,startIndex + regex.length());
            v.addElement(original.substring(index + 1 - regex.length()));
            str = new String[v.size()];
            for(int i=0;i<v.size();i++)
                str[i] = (String)v.elementAt(i);
            return str;
    }

    i haven't worked with devices but only with the toolkit emulators;
    it definitely is possible...
    u have to send the image as a bytestream and receive the image at the jsp end...
    and then reconstruct the image.
    the Stream classes in J2ME AND J2SE are all u will require.
    also the Image class.
    i have not done this but i have successfully sent an image frm a jsp and displayed it on the emulator.

  • Resgular Expression question

    Hi guys. I am a java programmer for a couple of years now but I could never learn regular expressions in this or any other language. My problem is that I want to use String's replaceAll method to replace all HTML structures from a string. Actually, I want to remove all <*>, ie all character between the angular brackets (together with teh brackets of course). Does anyone have any idea how this is done with regular expressions?
    replaceAll method is defined as follows:
    String      replaceAll(String regex, String replacement)
    Replaces each substring of this string that matches the given regular expression with the given replacement.
    Thanks in advance

    Hi,
    public class Test {
         public static void main(String[] args) {
              String test = "<img src=\"blah blah\">hello</img> and so on <br>.";
              System.out.println(test.replaceAll("<[^>]*>", ""));
    }Kaj
    Ps.
    Native methods is not the correct forum for this kind of questions. You should have posted in Java programming.

  • Regular Expressions and java

    hi everybody i have a little question:
    Does anybody have an idea how i can accomplish the following task:
    I want to have a regex that excludes words that contain a ++, --, __ but any word contains single occurence of these characters (+,-,_) should be matched.
    I tried anything that i could think of but i can't seem to be able to find a working regex. Anybody have an idea

    It took me a while to get my head around possessive
    quantifiers and atomic groups, and what they're good
    for. They can be a little tricky--Friedl
    himself got burned by them in the third edition of
    MRE, as shown in the errata for pages 481-2:
    http://regex.info/errata3.html
    It's good to see that even those living on Mt. Olympus can get it wrong sometimes.
    My version of Friedl is a correction on the first edition and is dated Nov 1997. In my version, 'possessive quantifiers' are proposed as a possible solution to a problem but Friedl does not mention any implementations. It may be time to fork out some cash and buy the latest version.

  • Java BeanShell expression in ODI

    hi experts,
    i am working on ODI 11 g (11.1.1)
    i have found java beanshell expression in standard ODI KM (IKM "IKM Oracle Slowly Changing Dimension", step 192 "Analyze integration table"):
    <%=odiRef.getTable("L","INT_NAME","A").replaceAll("","").replaceAll("..>",".replaceAll(odiRef.getInfo( \\u0022DEST_WORK_SCHEMA\\u0022 )+\\u0022.\\u0022,\\u0022\\u0022)?>")%>
    It translates, for example, "DWH_ETL.I$_SC_INTERMEDIARY" to "I$_SC_INTERMEDIARY"
    Please explain in detail how it works?
    specifically, i don't understand how works the expression:
    replaceAll("..>",".replaceAll(odiRef.getInfo( \\u0022DEST_WORK_SCHEMA\\u0022 )+\\u0022.\\u0022,\\u0022\\u0022)?>")
    Java function "replaceAll" (http://download.oracle.com/javase/6/docs/api/):
    public String replaceAll(String regex,
    String replacement)
    replaces each substring of this string that matches the given regular expression with the given replacement.
    What does mean the expression "..>" in this calling replaceAll?
    it looks like a nested call to the substitution API (http://www.business-intelligence-quotient.com/?p=812)
    thanks in advance

    HI,
    I have re configured as mentioned in your blog . But still getting same exception . Something I missed in my previous thread is below.
    <Sep 19, 2012 3:34:46 PM EDT> <Error> <HTTP> <BEA-101216> <Servlet: "AgentServlet" failed to preload on startup in Web application: "trellisagent".
    ODI-1400: Agent trellisagent start failure: JDBC connection error occurs while connecting to the master repository.
    Caused by: java.security.AccessControlException: access denied (oracle.security.jps.service.credstore.CredentialAccessPermission context=SYSTEM,mapName=oracle.odi.credmap,keyName=SUPERVISOR read)
    at oracle.odi.runtime.agent.servlet.AgentServlet.startup(AgentServlet.java:318)
    at oracle.odi.runtime.agent.servlet.AgentServlet.init(AgentServlet.java:226)
    at javax.servlet.GenericServlet.init(GenericServlet.java:242)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:283)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    I am stuck in asituation here :(
    Ashish

  • Dashes convert to single line

    Hello,
    On my iMac OS X 10.9.4, i am unable to create in TextEdit or Pages guitar tabs in the Courier font, like i did for years, by simply keeping my finger pressed on the dash key: all my dashes attach themselves together to form a continuous line as soon as i release the key! This behavior occurs in other typefaces—and in TextEdit in Plain Text as in Rich Text mode.
    This has never happened to me before—i may have some settings or preferences off somewhere, but i have not been able to sort my problem out from my System Preferences. As i have also Kotoeri, i tried out switching to the Romaji mode: same result. i even opened old tabs and copied-pasted the original tabs, but as soon as i start inserting more dashes, they turn into a single line too.
    I will be grateful to any fellow guitarist who will provide me with the solution, as i am clearly over my head with this! Thank you in advance.

    In Oracle 9 you can get rid of the regex functions and use traditional SUBSTR, INSTR and REPLACE:
    ABSOLUTELY NOT TESTED...
    SELECT col1,SUBSTR ( ','||col2||',', instr(','||col2||',',',',lvl)+1,instr(','||col2||',',',',lvl+1)-instr(','||col2||',',',',lvl)-1)
      FROM table_name,
           (SELECT LEVEL lvl
              FROM (SELECT MAX (LENGTH (REPLACE ( col2, ',',''))) mx
                      FROM table_name)
            CONNECT BY LEVEL <= mx + 1)
    WHERE lvl - 1 <= LENGTH (REPLACE ( col2, ',',''));Max

  • Single column value into two column of report

    Hi frnds,
    I have a column of Adress in my databse table from where i have to fetch values and show it a report
    able to get report but showing in single column if i take a printout paper will be wasted so I thought of passing these values to two different columns
    please help me in giving some suggestions

    In Oracle 9 you can get rid of the regex functions and use traditional SUBSTR, INSTR and REPLACE:
    ABSOLUTELY NOT TESTED...
    SELECT col1,SUBSTR ( ','||col2||',', instr(','||col2||',',',',lvl)+1,instr(','||col2||',',',',lvl+1)-instr(','||col2||',',',',lvl)-1)
      FROM table_name,
           (SELECT LEVEL lvl
              FROM (SELECT MAX (LENGTH (REPLACE ( col2, ',',''))) mx
                      FROM table_name)
            CONNECT BY LEVEL <= mx + 1)
    WHERE lvl - 1 <= LENGTH (REPLACE ( col2, ',',''));Max

  • Regular Expression / String question?

    Ok, So I want to do a String.split and split by a
    (.*)But since parenthese's are regex, how would I search for that without messing up the call?

    CButz wrote:
    so
    \(.*\)should work?Yup.
    But note that if the regex is Java string literal--that is, in your source code in double quotes, as opposed to being read from user input or a config file, you'll need to double the backslash.
    "\\(.*\\)"Also, note that that regex will match (abc)def(ghi) as one group. The abc)def(ghi will match the .*

  • Safari May Not Interpret Regular Expression in Compliance with W3C Standard

    We are troubleshooting why some websites are no longer working when rendered with the Safari 2.0.4 browser. The failure begins when client entered data is validated using regular expressions.
    We have localized the issue to Safari's not interpretting regular expressions consistently.
    For example:
    Does the regex \u00e9 match the literal character é? (Validates the regular expression engine understands Unicode escape sequences for extended characters.)? - NO, but it does on IE and FireFox
    Does the regex \u0041 match the literal character A? (Validates the regular expression engine understands Unicode escape sequences for ASCII characters.)? - NO, but it does on IE and FireFox
    Does the regex é match the literal character é? (Validates the regular expression engine understands literal characters outside the ASCII range – this is against ECMAScript spec.)? - Sometimes, but always on IE and FireFox
    Write a Unicode escape sequence to the screen on the client side. (Validates the string parsing and display in the JS engine works.) - Works on all 3
    Is escape sequence \u00e9 equivalent to literal character é? (Validates the string functionality in the JS engine works with extended characters.)? Yes on all 3.
    Is escape sequence \u0041 equivalent to literal character A? (Validates the string functionality in the JS engine works with ASCII characters.)? Yes on all 3
    Does the regex A match the literal character A? (Validates the regular expression engine understands literal characters in the ASCII range – this is ECMAScript spec.)? Yes on all 3
    Please help. It's hard for me to believe that the regular expression / javascript interpreter(s) for Safari aren't working as they have in the past - but all roads are pointed that way....
    Thank you for your review.
      Mac OS X (10.4.7)  

    We are troubleshooting why some websites are no longer working when rendered with the Safari 2.0.4 browser. The failure begins when client entered data is validated using regular expressions.
    We have localized the issue to Safari's not interpretting regular expressions consistently.
    For example:
    Does the regex \u00e9 match the literal character é? (Validates the regular expression engine understands Unicode escape sequences for extended characters.)? - NO, but it does on IE and FireFox
    Does the regex \u0041 match the literal character A? (Validates the regular expression engine understands Unicode escape sequences for ASCII characters.)? - NO, but it does on IE and FireFox
    Does the regex é match the literal character é? (Validates the regular expression engine understands literal characters outside the ASCII range – this is against ECMAScript spec.)? - Sometimes, but always on IE and FireFox
    Write a Unicode escape sequence to the screen on the client side. (Validates the string parsing and display in the JS engine works.) - Works on all 3
    Is escape sequence \u00e9 equivalent to literal character é? (Validates the string functionality in the JS engine works with extended characters.)? Yes on all 3.
    Is escape sequence \u0041 equivalent to literal character A? (Validates the string functionality in the JS engine works with ASCII characters.)? Yes on all 3
    Does the regex A match the literal character A? (Validates the regular expression engine understands literal characters in the ASCII range – this is ECMAScript spec.)? Yes on all 3
    Please help. It's hard for me to believe that the regular expression / javascript interpreter(s) for Safari aren't working as they have in the past - but all roads are pointed that way....
    Thank you for your review.
      Mac OS X (10.4.7)  

  • Help with Reg Expression Start method

    Hi there,
    I've been looking through some examples of regular expressions and I've became totally unglued at what the start method of the Matcher class returns.
    Here's the example...
    Passing in "\d*" ab34ef to the following code
    import java.util.regex.*;
    public class Class1
      public static void main(String []args)
        Pattern p= Pattern.compile(args[0]);
        Matcher m=p.matcher(args[1]);
        boolean b=false;
        while (b=m.find())
          int x=m.start();
          String y=m.group();
          System.out.print(x + y);
    }Gives the output
    01234456
    I understand eveything apart from the 6 character. How can m.start()return 0 (at the start) and 6 at the end when the string being searched is 6 characters long.
    My head hurts.

    The fact that a string is an array of characters under the hood is just an implementation detail, and it's getting in your way. What start() returns is the beginning position of a substring which may have a length of zero.
    The first time through the loop, the regex matches a zero-length substring at the beginning of the target string. That's the position preceding the first character, index 0. Then, because the match didn't consume any characters, the Matcher moves ahead one position before trying again. Another zero-length match, another bump-along, and now it's at index 2. This time, the regex can actually match some characters. It matches the substring "34", and that brings us to the part that's really confusing. Because the previous match consumed some characters, the Matcher doesn't do a bump-along before attempting the next match. It matches a zero-length substring at index 4, right where the previous match ended. Then it bumps along to index five and does another zero-length match.
    Now, you and I know that the character at index 5 is the last one in a string whose length is 6, so there's no reason to look for any more matches at this point. And if the regex were required to match at least one character, the Matcher wouldn't bother trying again. But in this case a zero-length match is considered valid, and there's one more position where that's possible. It does one last bump-along and matches nothing once more.

  • Xscertd spamming my console

    I'm getting tons of spam like this every minute :
    08/03/2014 09:49:12,308 sandboxd[89]: ([89837]) xscertd(89837) deny file-read-metadata /Library/Preferences/com.apple.security.plist
    08/03/2014 09:49:12,328 sandboxd[89]: ([89837]) xscertd(89837) deny file-read-data /Library/Preferences/com.apple.security.plist
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,000 kernel[0]: Sandbox: xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,914 sandboxd[89]: ([89837]) xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,934 sandboxd[89]: ([89837]) xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,954 sandboxd[89]: ([89837]) xscertd(89837) deny file-read-metadata /private
    08/03/2014 09:49:38,975 sandboxd[89]: ([89837]) xscertd(89837) deny file-read-metadata /private
    I'm not sure what's going on there.
    Anyone have a clue?

    I have the exact same issue on a newly rebuilt OS X Server. I can't imagine going through all that pain again to reinstall the OS and rebuild OS X Server. Are there other options?
    I have Profile Manager running, but switching it off doesn't stop the entries.  I also have local accounts on an external drive.
    Log entries:
    4/28/14 9:23:25.000 PM kernel[0]: Sandbox: xscertd(675) deny file-read-metadata /private
    4/28/14 9:23:25.000 PM kernel[0]: Sandbox: xscertd(675) deny file-read-metadata /private
    4/28/14 9:23:25.000 PM kernel[0]: Sandbox: xscertd(675) deny file-read-metadata /private
    4/28/14 9:23:45.183 PM servermgrd[95909]: could not convert interface name
    4/28/14 9:23:59.000 PM kernel[0]: Sandbox: xscertd(675) deny file-read-metadata /Volumes
    4/28/14 9:23:59.000 PM kernel[0]: Sandbox: xscertd(675) deny file-read-metadata /Volumes
    4/28/14 9:23:59.000 PM kernel[0]: Sandbox: xscertd(675) deny file-read-metadata /Volumes
    Here are the two certs files:
    ; Copyright (c) 2010 Apple Inc. All rights reserved.
    ; xscertd-helper sandbox profile
    (version 1)
    (deny default)
    (import "system.sb")
    (allow distributed-notification-post)
    (allow file-read*
           (regex #"^/Library/Keychains/.")
           (literal "/Library/Keychains/System.keychain")
           (literal "/Library/Preferences/com.apple.security.plist")
           (literal "/private/etc/openldap/ldap.conf")
           (regex #"^/private/var/db/mds/")
           (regex #"^/private/var/root/Library/Application Support/Certificate Authority/")
           (regex #"^.*/Library/Preferences/(ByHost/)?\.GlobalPreferences.*\.plist$")
           (literal "/private/var/root/Library/Preferences/com.apple.security.plist")
           (literal "/usr/libexec")
           (literal "/usr/libexec/xscertd")
           (literal "/usr/libexec/xscertd-helper"))
    (allow file-read-metadata
           (literal "/")
           (literal "/Library")
           (literal "/Library/Keychains")
           (regex #"^/Library/Keychains/System.keychain.")
           (literal "/Library/Keychains/apsd.keychain")
           (literal "/private")
           (literal "/private/var")
           (literal "/private/var/db")
           (literal "/private/var/db/mds")
           (literal "/private/var/db/mds/system")
           (literal "/private/var/root")
           (literal "/private/var/folders")
           (regex #"^/private/var/folders/")
           (literal "/private/var/run/systemkeychaincheck.done"))
    (allow file-write*
           (literal "/Library/Keychains/System.keychain")
           (regex #"^/Library/Keychains/System.keychain.")
           (literal "/private/var/log/xscertd.log"))
    (allow file-write-data
           (literal "/private/var/db/mds/system/mds.lock"))
    (allow ipc-posix-shm
           (ipc-posix-name "apple.shm.notification_center")
           (ipc-posix-name "com.apple.AppleDatabaseChanged"))
    (allow mach-lookup
           (global-name "com.apple.SecurityServer")
           (global-name "com.apple.distributed_notifications@1v3"))
    (allow network-outbound
           (literal "/private/var/run/ldapi")
           (literal "/private/var/run/mDNSResponder"))
    /usr/share/sandbox/com.apple.xscertd-helper.sb (END)
    ; Copyright (c) 2010 Apple Inc. All rights reserved.
    ; xscertd sandbox profile
    (version 1)
    (deny default)
    (import "system.sb")
    (deny job-creation
            (with no-log))
    (allow distributed-notification-post)
    (allow file-read*
           (regex #"^.*/Library/Preferences/(ByHost/)?\.GlobalPreferences.*\.plist$")
           (regex #"^/private/var/db/mds/")
           (literal "/private/var/db/DetachedSignatures")
           (literal "/usr/libexec")
           (literal "/usr/libexec/xscertd"))
    (allow file-read-metadata
           (literal "/")
           (literal "/Library")
           (literal "/Library/Keychains")
           (literal "/Library/Keychains/System.keychain")
           (literal "/private/var/db/DetachedSignatures")
           (literal "/private/var/empty")
           (literal "/private/var/run/systemkeychaincheck.done"))
    (allow file-write*
           (literal "/private/var/log/xscertd.log"))      
    (allow mach-lookup
           (global-name "com.apple.CoreServices.coreservicesd")
           (global-name "com.apple.SystemConfiguration.SCNetworkReachability")
           (global-name "com.apple.distributed_notifications@1v3")
           (global-name "com.apple.xscertd.helper"))
    /usr/share/sandbox/com.apple.xscertd.sb (END)

Maybe you are looking for

  • How do I open a .msg file...is it safe?

    Occasionally i get an email with a .msg file attached.  It is from a friend who is known to me.  How do I open it and is it safe? Thanks for the help.. kathy

  • What's the next update for iPod 4th generation

    What's the next update for iPod touch 4th generation. If there even is one!

  • My font has gone to Greek!

    Hey - I was ejecting a Cd from the CD-ROM drive, but when it wouldnt open I pressed it three times. Right after that the screen flashed to black and then reappeared as before. From that point on everything I type is seen as Greek and other assorted c

  • Can't I use nvraid without APIC on my MSI k8n neo2?

    I have a Windows XP installation without ACPI (Why would I want that?, you may ask.) The reason is that  it's a music production oriented installation, and I found that my soundcard performs much better with ACPI off. Well, I got 2 sata drives and se

  • Validation time period?

    I have submitted a new feed for approval http://www.fmcog.com/Podcast/RSS/Preach.xml   But I haven't received a validation email and its been over 12 days?  Last similar podcast I submitted only took 24hrs to validate.  Are waiting periods longer now