String.matches() faulty?

I wondered why my regExp didn't work when I called it with
myString.matches(searchString);So I wrote this test code:
        System.out.println("Test: if substring exists:");
        String text = "Using org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser as SAX2 Parser";
        String search = "as SAX2 Parser";
        String regExp = "\\S*("+search.toUpperCase()+"\\S*)";
        Pattern pat = Pattern.compile(regExp);
        Matcher m = pat.matcher(text.toUpperCase());
        while (m.find()) {
            System.out.println("found2: "+text.substring(m.start(), m.end()));
        System.out.println("Same with String.matches:");
        System.out.println("found2: "+text.matches(regExp));and the first custom code matches the regExp and the String.matches() doesn't match. What's the catch?

"abc" -> find ("b") -> finds "b"
"abc".matches("b") -> returns false
"b".matches("b") -> returns false
"abc".matches(".b.") > returns trueIf you'd like you could say that matches assumes an
implicit "^" at the beginning and an "$" at the end
of your regex. It tries to match the entire
string and if it doesn't capture it all it returns
false.Why is
"b".matches("b") -> returns false?

Similar Messages

  • The case structure is not working well on comaring two strings using true or false string matching VI

    I need an execution of commands after the reply from the instrument matches with the string I provided for that i used true or false string match VI on which the true string the matching command and the string is the reply from the instrument. And I put the further executionable commands in frame after frame of sequence loop in the true of the case structure. Amd finally I given all the output strings to the concatenate string to get all the replies as one loop. But when I execute the program the desired result is not available. So kindly please help me to overcome this problem.  
    Attachments:
    basic serial with changes.vi ‏24 KB

    You VI makes absolutely no sense and I would recommend you start with a few simple LabVIEW tutorials before trying to tackle this.
    What is the point of the FOR loop with 1 iteration, it might as well not even be there, same difference.
    Why is there an abort primitive in the FOR loop, this mean the program will unconditionally stop abort before any downstream code will ever go into action. The program will never get past the FOR loop.
    You created a circular data dependency and LabVIEW inserted a feedback node automatically, making things even worse. (see also)
    You need to learn about dataflow, execution order, and data dependency.
    You need to learn about the various types of tunnels (plain, autoindexing, etc.)
    There is a tremendous amount of duplicate code. Large code sections are the same, differeing only by a string. You should only have one copy of that code inside a proper state machine. Have a look at the design templates and examples that ship with LabVIEW.
    LabVIEW Champion . Do more with less code and in less time .

  • An additional question about regular expressions with String.matches

    does the String.matches() method match expressions when some substring of the String matches, or does it have to match the entire String? So, if i have the String "123ABC", and i ask to match "1 or more letters" will it fail because there are non-letters in the String, but then pass if i add "1 or more letters AND 1 or more digits"? so, in the latter every character in the String is accounted for in the search, as opposed to the first. Is that correct, or are there ways to JUST match some substring in the String instead of the whole thing? i WILL make some examples too... but does that make sense?

    It has to match the whole String. Use Matcher.find() to match on just a sub-string()

  • String.matches vs Pattern and Matcher object

    Hi,
    I was trying to match some regex using String.matches but for me it is not working (probably I am not using it the way it should be used).
    Here is a simple example:
    /* This does not work */
    String patternStr = "a";
    String inputStr = "abc";
    if(inputStr.matches( "a" ))
    System.out.println("String matched");
    /* This works */
    Pattern p = Pattern.compile( "a" );
    Matcher m = p.matcher( "abc" );
    boolean found = false;
    while(m.find())
    System.out.println("Matched using Pattern and Matcher");
    found = true;
    if(!found)
    System.out.println("Not matching with Pattern and Matcher");
    Am I not matches method of String class properly?
    Please throw some lights on this.
    Thank you.

    String.matches looks at the whole string.
    bsh % "abc".matches("a");
    <false>
    bsh % "abc".matches("a.*");
    <true>

  • Contains return all the records when the query string matches the columns

    I used the multi_column_datastore preference and created an index on three columns (item_name, description,owner_part_number). Now if I do a search:
    select * from items where contains(description, 'description') > 0;It returns all the rows in items table, but not all the rows have "description" as a word. I guess Oracle text assumes the query intends to get all the rows as the query string matches one of the column names. My question is whether Oracle Text has any preference settings to alter this behavior?
    execute ctx_ddl.create_preference('item_multi_preference', 'MULTI_COLUMN_DATASTORE');
    execute ctx_ddl.set_attribute('item_multi_preference', 'columns', 'item_name, description,owner_part_number');
    create index item_text_index on items(description) indextype is ctxsys.context filter by owner parameters('LEXER ENG_LEXER WORDLIST ENG_WORDLIST STOPLIST CTXSYS.EMPTY_STOPLIST datastore item_multi_preference MEMORY 1024M');Thanks.
    Jun Gao

    It looks like a basic_section_group fixes the problem as well, as demonstrated below and I believe a basic_section_group may be more efficient than auto_section_group.
    SCOTT@orcl_11gR2> -- recreation of problem:
    SCOTT@orcl_11gR2> drop table items
      2  /
    Table dropped.
    SCOTT@orcl_11gR2> create table items (
      2       "ITEM_NAME"             varchar2(100 byte),
      3        "ITEM_NUMBER"              varchar2(100 byte),
      4        "DESCRIPTION"              varchar2(4000 byte),
      5        "OWNER" number
      6  )
      7  /
    Table created.
    SCOTT@orcl_11gR2> begin
      2    FOR Lcntr IN 1..100
      3    loop
      4         insert into items (item_name, item_number, description, owner)
      5         values (dbms_random.string('A', 10),
      6              dbms_random.string('A', 10),
      7              dbms_random.string('L', 8) || ' '
      8              || dbms_random.string('A', 4)
      9              || dbms_random.string('A', 5)  || ' '
    10              || dbms_random.string('A', 10),
    11              dbms_random.value(1,10) );
    12    end loop;
    13  end;
    14  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    FOR Lcntr IN 1..100
      3    loop
      4         insert into items (item_name, item_number, description, owner)
      5         values (dbms_random.string('A', 10),
      6              dbms_random.string('A', 10),
      7              dbms_random.string('L', 8) || ' '
      8              || dbms_random.string('A', 4) || '111'
      9              || dbms_random.string('A', 5)  || ' '
    10              || dbms_random.string('A', 10), 1234 );
    11    end loop;
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> exec ctx_ddl.drop_preference('ENG_WORDLIST');
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_preference('ENG_WORDLIST', 'BASIC_WORDLIST');
      3    ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_INDEX','TRUE');
      4    ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_MIN_LENGTH',1);
      5    ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_MAX_LENGTH',10);
      6    ctx_ddl.set_attribute('ENG_WORDLIST','SUBSTRING_INDEX','TRUE');
      7    ctx_ddl.set_attribute('ENG_WORDLIST','WILDCARD_MAXTERMS', 0);
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> execute ctx_ddl.drop_preference('ENG_LEXER');
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    CTX_DDL.CREATE_PREFERENCE ('ENG_LEXER', 'BASIC_LEXER');
      3    CTX_DDL.SET_ATTRIBUTE ('ENG_LEXER', 'PRINTJOINS', '@-_');
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> execute ctx_ddl.drop_preference('items_multi_preference');
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_preference('items_multi_preference', 'MULTI_COLUMN_DATASTORE');
      3    ctx_ddl.set_attribute('items_multi_preference', 'columns', 'item_name, description,item_number');
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> create index items_text_index
      2  on items(description)
      3  indextype is ctxsys.context
      4  parameters
      5    ('LEXER         ENG_LEXER
      6        WORDLIST   ENG_WORDLIST
      7        STOPLIST   CTXSYS.EMPTY_STOPLIST
      8        datastore  items_multi_preference
      9        MEMORY     1024M')
    10  /
    Index created.
    SCOTT@orcl_11gR2> create index owner_idx on items (owner)
      2  /
    Index created.
    SCOTT@orcl_11gR2> exec dbms_stats.gather_table_stats (user, 'ITEMS')
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> select count(*)
      2  from   items
      3  where  contains (description, 'description') > 0
      4  /
      COUNT(*)
           200
    1 row selected.
    SCOTT@orcl_11gR2> -- correction of problem:
    SCOTT@orcl_11gR2> exec ctx_ddl.drop_section_group ('items_sec')
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_section_group ('items_sec', 'basic_section_group');
      3    ctx_ddl.add_field_section ('items_sec', 'item_name', 'item_name', true);
      4    ctx_ddl.add_field_section ('items_sec', 'description', 'description', true);
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> drop index items_text_index
      2  /
    Index dropped.
    SCOTT@orcl_11gR2> create index items_text_index
      2  on items(description)
      3  indextype is ctxsys.context
      4  parameters
      5    ('LEXER         ENG_LEXER
      6        WORDLIST   ENG_WORDLIST
      7        STOPLIST   CTXSYS.EMPTY_STOPLIST
      8        datastore  items_multi_preference
      9        MEMORY     1024M
    10        section group items_sec')
    11  /
    Index created.
    SCOTT@orcl_11gR2> select count(*)
      2  from   items
      3  where  contains (description, 'description') > 0
      4  /
      COUNT(*)
             0
    1 row selected.

  • Email Regular Expression with a String.Match()

    I'm currently using a RichTextEditor for a user to build HTML
    for a site. However, I want the application to scan for emails and
    encode them so they are protected from spam bots when they go to
    the live site. I've written a regular expression to find an email
    and it seems to work, but it only returns one email at a time from
    the string. I have had to revert to a while loop to traverse the
    string until I'm satisfied. I don't particularly like that method
    and would like to just do one String.match() query to retrieve all
    of the emails. Can anyone see something here that I'm missing?

    Try adding the global flag (g):
    var emailPattern:RegExp =
    /[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]+/g;
    TS

  • Cannot get regular expression to return true in String.matches()

    Hi,
    My String that I'm attempting to match a regular expression against is: value=='ORIG')
    My regular expression is: value=='ORIG'\\) The double backslashes are included as a delimiter for ')' which is a regular expression special character
    However, when I call the String.matches() method for this regular expression it returns false. Where am I going wrong?
    Thanks.

    The string doesn't contain what you think it contains, or you made a mistake in your implementation.
    public class Bar {
       public static void main(final String... args) {
          final String s = "value=='ORIG')";
          System.out.println(s.matches("value=='ORIG'\\)")); // Prints "true"
    }

  • String.matches() question - regular expression help

    How come the following code's if condition returns false?
    String someFile="Dr. Phil.pdf";
    if (someFile.matches("[.][Pp][Dd][Ff]$")) {
      System.out.println("File is a pdf file.");
    }When I change the the matches method to matches(".*[Pp][Dd][Ff]$") it works, so does that mean it has to match the entire string to return true? If so, how can I determine if a partial match occured?
    If partial matching isn't feasible, then can someone help me look determine if this is the best matching pattern to use:
    matches(".*[.][Pp][Dd][Ff]$")Thanks.

    The documentation is your friend.
    [String.matches(regex)|http://java.sun.com/javase/6/docs/api/java/lang/String.html#matches(java.lang.String)] says:
    An invocation of this method of the form str.matches(regex) yields exactly the same result as the expression
    Pattern.matches(regex, str)And [Pattern.matches(regex, str)|http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#matches(java.lang.String, java.lang.CharSequence)] says
    behaves in exactly the same way as the expression
    Pattern.compile(regex).matcher(input).matches()And [Matcher.matches()|http://java.sun.com/javase/6/docs/api/java/util/regex/Matcher.html#matches()] says
    Attempts to match the entire region against the pattern.

  • How can I search for an exact string match in my emails?

    I was looking for an old email that I had about Re-Animator The Musical. So, in the search bar in the upper right corner of the Thunderbird window, I typed "re-animator". I got 59 hits, and the message that actually contained the string "re-animator" was 27th, when sorted by relevance. All of the other hits were emails which contained the word "animal" or "animals", which to me has nothing to do with "re-animator". I'm surprised that those were considered hits at all, much less that they were considered more relevant than the one message which actually contained the desired string.
    I actually tried three different searches:
    reanimator
    re-animator
    "re-animator"
    (i. e. the first two were without quotes and the third was with quotes). All three of these variations had the same problem, though, that messages containing "animal" were ranked before the message containing "re-animator".
    The desired message contained the word "Re-Animator" (with that capitalization and hyphenation), and also contained "reanimatorthemusical" as part of a URL that was mentioned in the message. So, I would have expected both the search with the hyphen and the search without the hyphen to have been good hits for this message.
    My question is: How can I tell Thunderbird to search for messages that literally contain the string I ask for, and not get "creative" with the matches, as it seems to be doing for some reason?
    (I'm using Thunderbird 31.3.0 on Mac OS X 10.9.5.)

    No, searching for:
    "Animator" musical
    still has the exact same problem: it still wants to find "animal" instead of "animator". Why?
    Yes, I had already read the support article you linked to, but I hadn't found anything in it about why Thunderbird would prefer "animal" over "animator", or how to disable this misfeature. Is there no better documentation for the search bar than that?
    (And the search for "Animator The Musical" didn't find my message, simply because my message didn't contain that exact string. It contained "I am on a waiting list for some musical tickets for Sunday, but I haven't heard back yet. It is a preview of The Re-Animator. ( http://www.reanimatorthemusical.com/ )." The search for "Animator The Musical" only had a single hit, your message in which you suggest searching for that.)

  • Exact String match when calling a recordset

    I have a CategoryID column, and a Cats column.
    The main catefory for that products is on CategortID, but the in the Cats column is a string of other categories that the item is listed in.
    The problem is that if the search is for category id 94, and the Cats column includes 194 the item gets shown.
    How so I create a recordset that only returns items that match exactly out of the sting.
    I am currently using
    WHERE (Categoryid = colname or (INSTR(Cats, colname) >= 1))
    Here is an example
    Item CategoryID = 139
    Cats = 187, 136, 194
    But searching for category id displays this item!
    Any help appreciated

    Instead of INSTR(), try using FIND_IN_SET()
    WHERE (Categoryid = colname or (FIND_IN_SET(Cats, colname) >= 1))
    FIND_IN_SET() is meant to be for strings, so it might not work. But it does look for a complete match in a comma-separated list. Make sure there is no space between the comma and number when stored.

  • Forcing an exact string match in searches

    Is there a way of using the Case Exact String and Case Ignore String plugins so I can ensure that the iPlanet directory server only returns exact matches to an LDAP client.
    e.g.the difference in
    ldapsearch "cn=Abc"
    ldapsearch "cn=ABC"
    I want to find only "ABC" and NOT Abc or abc or aBc and so on..

    You can accomplish this using extensible matching rules.
    By default, the cn attribute is not case-sensitive. You can search for a case-sensitive cn value with a search filter like:
    cn:2.5.3.15:=ABC
    This will use the 2.5.3.15 (Case Exact Match) matching rule on the cn attribute. Note that this search will not be indexed, however, and will take longer than a normal cn search for an exact value.
    You can find more information on extensible matching in RFC 2254 (http://www.ietf.org/rfc/rfc2254.txt).

  • Regular expressions and string matching

    Hi everyone,
    Here is my problem, I have a partially decrypted piece string which would appear something like.
    Partially deycrpted:     the?anage??esideshe?e
    Plain text:          themanagerresideshere
    So you can see that there are a few letter missing from the decryped text. What I am trying to do it insert spaces into the string so that I get:
                        The ?anage? ?esides he?e
    I have a method which splits up the string in substrings of varying lengths and then compares the substring with a word from a dictionary (implemented as an arraylist) and then inserts a space.
    The problem is that my function does not find the words in the dictionary because my string is only partially decryped.
         Eg:     ?anage? is not stored in the dictionary, but the word �manager� is.
    So my question is, is there a way to build a regular expression which would match the partially decrypted text with a word from a dictionary (ie - ?anage? is recognised and �manager� from the dictionary).

    I wrote the following method in order to test the matching using . in my regular expression.
    public void getWords(int y)
    int x = 0;
    for(y=y; y < buff.length(); y++){
    String strToCompare = buff.substring(x,y); //where buff holds the partially decrypted text
    x++;
    Pattern p = Pattern.compile(strToCompare);
    for(int z = 0; z < dict.size(); z++){
    String str = (String) dict.get(z); //where dict hold all the words in the dictionary
    Matcher m = p.matcher(str);
    if(m.matches()){
    System.out.println(str);
    System.out.println(strToCompare);
    // System.out.println(buff);
    If I run the method where my parameter = 12, I am given the following output.
    aestheticism
    aestheti.is.
    demographics
    de.o.ra.....
    Which suggests that the method is working correctly.
    However, after running for a short time, the method cuts and gives me the error:
    PatternSyntaxException:
    Null(in java.util.regex.Pattern).
    Does anyone know why this would occur?

  • Regular Expressions / String Match

    Hi Everyone,
    thankx for reading this
    I'm programing a oracle form which at one part read's the full path into a file (a text file) and place's it on a VARCHAR2 field. This is the path into the file and not the file data.
    I would like to match this string (the file path) to a another one (in order to know if the file name respect some rules). This is a very easy thing to do under Perl / PHP and other languages. But how can i do this under PL/SQL ?
    I have search but failed to find any clue.
    Any pointers would be great, or a small example
    Thankx Stay Happy
    Miguel Angelo

    Hi,
    you can use INSTR and SUBSTR for String comparison
    INSTR(char1,char2) shows you the first occurence of char2 in char1
    INSTR(char1,char2,n,m)
    shows the m'th occurence of char2 in char1 starting on n
    Frank

  • Finding string matches in an arraylist

    Hi,
    I have been bashing my head with this for a while, so any help is much appreciated!
    I bascially have ONE arraylist which contains filenames as strings (e.g. file.txt, file1.xml, file2.doc, file2.xml, file2.txt)
    The arraylist bascially contains a document name with there associated metadata document names. For example file1.doc (document file), file1.xml (metedata file).
    There will be siuations where for example file1.doc may not have an associated file1.xml file with it. And there may be situations where there are 2 documents and only one associated metadata file (e.g. file.doc, file1.txt, file1.xml)
    I basiclaly need to loop arond the arraylist identifying only files names that:
    - have an associated metadatafile (once identified put the document name in an arraylist of matches)
    -this arraylist cannot contain duplicate documents with an associated file name (e.g. file.doc, file1.txt, file1.xml), if this particualr situations occurs I want to put these filenames in an arraylist of errors.
    Please help! thanks in advance

    Hi,
    I have been bashing my head with this for a while, so
    any help is much appreciated!
    I bascially have ONE arraylist which contains
    filenames as strings (e.g. file.txt, file1.xml,
    file2.doc, file2.xml, file2.txt)Ok
    >
    The arraylist bascially contains a document name with
    there associated metadata document names. For example
    file1.doc (document file), file1.xml (metedata
    file).
    When you have different pieces of data that have an association with each other (such as your file name String and associated metadata file) you should consider writing a Class to model that association (with the data elements as members). Not only does this more closely reflect what's really going on, but it can save you work (both thinking and coding) later on.
    There will be siuations where for example file1.doc
    may not have an associated file1.xml file with it.
    And there may be situations where there are 2
    documents and only one associated metadata file (e.g.
    file.doc, file1.txt, file1.xml)
    Looks like this new Class needs a List of file names
    I basiclaly need to loop arond the arraylist
    identifying only files names that:
    - have an associated metadatafile (once identified
    put the document name in an arraylist of matches)You could simply have a "hasMetadata()" method in your new class and call it.
    -this arraylist cannot contain duplicate documents
    with an associated file name (e.g. file.doc,
    file1.txt, file1.xml), By overriding the equals method in your new class you can use the contains method of the List.
    if this particualr situations
    occurs I want to put these filenames in an arraylist
    of errors.
    Please help! thanks in advanceGood Luck
    Lee

  • A regular expressin problem: String.matches & the pair of Pattern & Matcher

    I observe this problem when working on pattern match for Z5Z-5Z5, Z5Z 5Z5 or Z5Z5Z5.
    When I use the match method of the String class, the correct pattern will yield true with
    !str.matches("^[A-Za-z]\\d[A-Za-z]\\s?|-?\\d[A-Za-z]\\d$").
    When I use the pair classes of regex:
    Pattern p = Pattern.compile("^[A-Za-z]\\d[A-Za-z]\\s?|-?\\d[A-Za-z]\\d$");
    Matcher m = p.matcher(str);
    a string of "v7u h4e" (two blank spaces in between) can pass the !m.find().
    Have anyone else experienced the same situation?
    Do I use them right, or bugs?
    Thanks for your input.
    v.

    This is why I wish regex references would list the
    operator precedence. What do you mean? My regex reference does show that right under the section called "Operators" in the second chapter.
    Maybe you need to update your references and buy "Programming Perl"? :)
    I think there are only three
    levels of precedence, but it needs to be crystal clear
    that | has the lowest precedence (even lower than
    putting two tokens together!) and often needs
    parentheses: "\w\d|\s\w" means "(\w\d)|(\s\w)", not
    "\w(\d|\s)\w".Actually for that particular operator it is pretty consistent. It is always very low. Even when I was introduced to the theory of regex's in school the precedence was lower than everything else.

Maybe you are looking for

  • POP-UP In PO & PR

    Hi,         We are using PS Module.PR is generated thru PS only.now if we change the value of material in PR,system should give the POP-UP message "that material cost is more than projected cost:. is there any standard functionality. or we can use BA

  • I am having a problem with skins

    I have tried to add different types of skins, not changing anything. However, the only thing that appears like the skin I have chosen is the Contents panel. Other navigation appears on grey tabs. Also the Search Tab just shows the alphabet with all k

  • Reading the word under the cursor within MS Word

    I saw a very interesting article yesterday. Reading the word under the cursor And confirmed it today. Yes, it works fine with me. But, it works only with Notepad. It, even, does not work with Visual Studio itself. (Of course not with Notepad++ too.)

  • Help on import server

    Hi friends, please provide full configuration file for mds.ini(server), mdis.ini(import server) and mdss.ini (syndication server) [email protected] Thank you S Naidu shankar

  • Qosmio G30-182: Drops Wlan connection & then cannot find any Wlans

    I currently use driver v.11.1.0.100 for Intel(R) Pro/Wireless 3945ABG, which is the latest driver I found here at Toshiba. My problem is that I randomly lose my wifi connection, both at my home wlan (using WEP protection) and at my university (WPA-En