Wildcard charcters in strings

I need to write a program to search a bunch of strings from user input, which can include the wildcard characters '?' and '*'
'?' matches a single character, and '*' matches zero or more characters.
For eg, "bi?" returns "big", "bin", etc.
And "ant*" would return "ant", "ants", "anthill", etc.
I've found the '?' quite easy, but I'm having trouble with the '*'. How do I search through a data stucture (like a linked list or tree stucture) to find words that match things like "bi*s", or "*as?"

I ended up learning how to use the String.matches() method. Thanks a lot. I'm now wiser about regular expressions too.
I was going to try flounder's method of startsWith and endsWith, or tokenizing the string, but the problem ten beomes a lot more complicated when multiple wildcard characters are used...
But, it's all good now, my program works fine. Thanks for the help everyone.

Similar Messages

  • [3.1] InfoView Search - Use of Wildcards in Search string

    Hi,
    Is it possible to use wildcards like % or ? or _ or ... in InfoView search?
    Thanks for feedback!
    Raf

    what do you mean infoview search? are you searching for any document? or you have a report and you would like use wild card?
    if it is first one, just type in the word in the search box and enter. it brings all objects with that name. no need to use wild cards.
    if it is in the report, yes. in the where clause change the operator to matches pattern and in the operand type in the word and use the wild card.

  • How to find length of string after encryption using DBMS_CRYPTO package

    Hi,
    I am planning do data encryption using DBMS_CRYPTO package. I want to find how much will be string length after encryption.
    e.g When I try to encrypt string of length between 1-15 characters it gives me encrypted string of 32 characters. When I try with 16 charcters encrypted string is of 64 characters.
    Is ther any formula to calculate length of encrypted string?
    Thanks
    Pravin

    The length change is dependent upon the algorithm you are using which can be a combination of cipher block, padding, and chaining.
    The best solution is determine the method you are going to use and apply it to the l ongest possible strings you are going to proces, then add some safety margin. There iis no penalty for defining your column as VARCHAR2(4000).

  • Please have a look at this query

    hi there,
    i'm implementing a wildcard search utility in my app (restricting usage by allowing to use '*' & '?' only, so no hectic job here), i've achieved the correct matching of a given text & a text with wildcards but to some extent by manual check which very hectic to me, now i want to try with new code which is (incomplete) as follows, please correct & suggest me,
    class WildcardSearchUtility {
        static boolean isNodeStringMatchingWildcardText(String wcText, String nodeText) {
             char    c1[] = wcText.toCharArray();
             char    c2[] = nodeText.toCharArray();
             int     n1 = c1.length;
             int     n2 = c2.length;
             int   i1 = 0;
             int   i2 = 0;
             for ( ;     i1 < n1   &&   i2 < n2;     i1++, i2++) {
                if(c1[i1] == '*') {
                          // don't know what to do
                   if(i1 != (n1-1)) {
                      i1++;
                } else if (c1[i1] == '?') {
                          // don't know what to do
                   if(i1 != (n1-1)) {
                      i1++;
                } else if(c1[i1] != c2[i2])
                   return false;
             return false;
       }when i implement the code it should correctly match the given text and a wildcard search text, for example:
         String    wildcardText = "*L?st*";
         String    nodeTexts[] = {
              "List",   "ActionListener",   "JComponent",   "SomeText",
              "Last",   "AbstractList",     "JButton",      "Component"
              "Like",   "ABCDLastPQRS"
         System.out.println("Search text is " + wildcardText + "\n");
         for(int i=0; i < nodeTexts.length; i++) {
              boolean matching = WildcardSearchUtility.isNodeStringMatchingWildcardText(
                                    wildcardText, nodeTexts);
    System.out.println(
    "\tmatching with \""+ nodeTexts[i] + "\"\t" +
    (matching ? "[Matched]" : "[Not Matched]\n");
    System.out.println("Done");
    the output must be like the one below
    Search text is "*L?st*"
             matching with "List"         [Matched]
             matching with "ActionListener"         [Not Matched]
             matching with "JComponent"         [Not Matched]
             matching with "SomeText"         [Not Matched]
             matching with "Last"         [Matched]
             matching with "AbstractList"         [Matched]
             matching with "JButton"         [Not Matched]
             matching with "Component"         [Not Matched]
             matching with "Like"         [Not Matched]
             matching with "ABCDLastPQRS"         [Matched]
    Donei'd appreciate any suggestions, sample codes, corrections by you experts
    thanx in advance,
    Afroze.

    the jdk1.4 comes with regular expression treatment ...
    here it is a sample code:
    to test:
    * A class which provide a way of filtering a folder relative a set of filename masks
    * @version 1.0
    * @author Felipe Ga�cho
    public class teste
       static public void main(String[] args)
          MyFileFilter t = new MyFileFilter(new String[]{"*.jpg","i*o*u","*88*"});
          System.out.println(t.accept("teste.jpg"));
          System.out.println(t.accept(".jpg.jpg.jpge"));
    }The filter class:
    import java.util.*;
    import java.io.*;
    * A class which provide a way of filtering a folder relative a set of masks
    * @version 1.0
    * @author Felipe Ga�cho
    * @date september - 2001
    class MyFileFilter implements FileFilter
         /** The array of valid masks */
       private Object[][] masks = null;
       /** The wildcard. The default wildcard is the character '*' */
       private String wildcard = "*";
       /** The description of this filter. For example: "JPG and GIF Images" */
       String filterDescription = "";
         * The constructor
         * @param setOfMasks A set of masks which will be used as filter
       MyFileFilter(String[] setOfMasks, String description)
              filterDescription = description;
          masks = new Object[setOfMasks.length][];
          for(int i=0; i<setOfMasks.length; i++)
             masks[i] = parseMask(setOfMasks);
         * The constructor
         * @param setOfMasks A set of masks which will be used as filter
    MyFileFilter(String[] setOfMasks)
              this(setOfMasks, "");
         * Sets the character used as wildcard
         * @param wildcard The new wildcard character
    public void setWildcard(String newWildcard)
              wildcard = newWildcard;
         * Returns the current wildcard character
         * @return The current wildcard character
    public String getWildcard()
              return this.wildcard;
         * Creates an array with all tags of a mask
         * @param mask The mask which will be used to filter a folder
    private Object[] parseMask(String mask)
              StringTokenizer maskParser = new StringTokenizer(mask, wildcard, false);
              ArrayList maskTags = new ArrayList();
              // Fill the array of tags representation of the mask
              while(maskParser.hasMoreTokens())
                   maskTags.add((String)maskParser.nextToken());
              // Check if the first character of the mask is a wildcard (open mask on left)
              if(mask.startsWith(wildcard))
                   maskTags.add(0,wildcard);
              // Check if the last character of the mask is a wildcard (open mask on right)
              if(mask.endsWith(wildcard))
                   maskTags.add(wildcard);
              return maskTags.toArray();
         * The validation process: the filename is parsed from the left to the right
         * seeking the mask tags. If a tag in the mask can�t be reached
         * in the filename it return false, otherwise it returns true.
         * @param filename The filename to be test
         * @param mask An array containing the mask tags
    private boolean valid(String filename, Object[] mask)
              // Test if the first tag of the mask is present at the start of the filename
    if( ! mask[0].equals(wildcard) && ! filename.startsWith((String)mask[0]))
    return false;
              // Test if the last tag of the mask is present at the end of the filename
    if( ! mask[mask.length-1].equals(wildcard) && ! filename.endsWith((String)mask[mask.length-1]))
    return false;
    for(int i=0; i<mask.length; i++)
                   // If the tag is a wildcard, then ignore this tag and continues the verification
                   if(mask[i].equals(wildcard))
                        continue;
                   // The index of a non-wildcard tag in the filename
                   int indexOfTheTag = filename.indexOf((String)mask[i]);
                   if(indexOfTheTag == -1)
                        return false;
                   // The tag were found. Continues the verification from the tag index plus its length
                   filename = filename.substring(indexOfTheTag + ((String)mask[i]).length());
              return true;
         * Check if a filename is like one of the masks
         * @param filename The filename to be checked
    public boolean accept(String filename)
    for(int i=0; i<masks.length; i++)
    if(valid(filename, masks[i]))
    return true;
    return false;
    * The FileFilter method overwrite
    * @param filename The File which the name should be verifyied
    public boolean accept(File filepath)
    return accept((filepath.getName()).substring(filepath.getName().lastIndexOf(File.separator)));
    * The FileFilter method overwrite
    * @return The description of this file filter
    public String getDescription()
    return filterDescription;

  • Wild character

    Hello,
    i have an input string to the procedure which is Varchar type
    I wanted to find out if this input contains any wild characters, ie other than (A,B...Z , 0,1,2........9 )
    if the input contains otherthan alphanumeric then it should give throw an exception using raise application error.
    how do i find out?
    thank you

    or
    SQL> -- to return rows that have wildcard character in the string
    SQL> with virtual_tab as
      2   (select 'This has wildcard (%) in the string'       col1 from dual union all
      3    select 'This does not have wildcard in the string' col1 from dual)
      4  select col1
      5    from virtual_tab
      6   where instr(col1,chr(37)) > 0;
    COL1
    This has wildcard (%) in the string
    SQL> -- to return rows that does not have any wildcard character in the string
    SQL> with virtual_tab as
      2   (select 'This has wildcard (%) in the string'       col1 from dual union all
      3    select 'This does not have wildcard in the string' col1 from dual)
      4  select col1
      5    from virtual_tab
      6   where instr(col1,chr(37)) = 0;
    COL1
    This does not have wildcard in the string
    SQL>

  • [svn] 1751: Bug: BLZ-174 - MessageClient.testMessage() is incorrectly doing a string compare for the subtopic header of an inbound message against the subtopic value (which may contain wildcards) that the Consumer is using.

    Revision: 1751
    Author: [email protected]
    Date: 2008-05-15 14:21:43 -0700 (Thu, 15 May 2008)
    Log Message:
    Bug: BLZ-174 - MessageClient.testMessage() is incorrectly doing a string compare for the subtopic header of an inbound message against the subtopic value (which may contain wildcards) that the Consumer is using.
    QA: No - customer verified the fix.
    Doc: No
    Ticket Links:
    http://bugs.adobe.com/jira/browse/BLZ-174
    Modified Paths:
    blazeds/branches/3.0.x/modules/core/src/java/flex/messaging/MessageClient.java
    blazeds/branches/3.0.x/modules/core/src/java/flex/messaging/services/MessageService.java

    If you create a metadatatype with a single metdata block, and you reference that in your vm/cm cell attribute using a *one* based index, Excel seems to see the link and it honors it when saving the spreadsheet.
    So, I ended up with something like:
    <c ... cm="1"/> (I'm dealing with cell metadata, but the concept is equivalente to value metadata)
    <metadataTypes count="1">
      <metadataType name="MyMetaType" .../>
    </metadataTypes>
    <futureMetadata count="1" name="MyMetaType">
      <bk>
        <extLst><ext
    uri="http://example" xmlns:x="http://example"><x:val>87</x:val></ext></extLst>
      </bk>
    </futureMetadata>
    <cellMetadata count="1">
      <bk><rc
    t="1" v="0"/></bk> <!-- this is what gets referenced as cm=1 on the cell -->
    </cellMetadata>
    Hope this helps. 

  • Using wildcards in strings

    Hi all, I was wondering if it's possible to use wildcards in NSStrings?
    So for example say my text is:
    "The quick brown fox jumps over the lazy dog".
    And I want to extract the string "quick brown fox".
    Something like?
    (@"quick*fox");
    Is there a wildcard that can be used to extract the text between quick and fox? I know I could just strip out 'quick brown fox', but what if I didn't necessarily know it was 'brown' between them, and it was some other word?
    Thanks a bunch!

    There are a couple of regex libraries in the open source.

  • Wildcards in string matching?

    Right now I have a "fraction converter" class that looks, in part:
    case "6":
    case "66":
    case "67":
    case "68":
    case "666":
         theNumber = "2/3";
         break;
    Is there any way to use a wildcard or regex  in these case statements, so that I can say "6 followed by anything"?

    You coud try something like this, just grab the first number
    var tmpStr:String = String(myNumber).charAt(0);
    switch(tmpStr)
    case "6": theNumber = 2/3;
    David

  • Using wildcards for String compare

    Hello,
    I want my prog to find out all Strings which start with the letters 'File'. How can I make a String compare by using wildcards ?
    Thanx,
    Findus

    You may use the String method startsWith to find strings beginning with File. eg. filename.startsWith("File")
    for more complicated comparisons you might want to use regular expressions.

  • [svn:fx-trunk] 13501: Bug: BLZ447 - AMF3 Deserialization: Wrongly counted reference ID of duplicated String when in the same message there are Strings with only wildcards

    Revision: 13501
    Revision: 13501
    Author:   [email protected]
    Date:     2010-01-14 06:01:23 -0800 (Thu, 14 Jan 2010)
    Log Message:
    Bug: BLZ447 - AMF3 Deserialization: Wrongly counted reference ID of duplicated String when in the same message there are Strings with only wildcards
    QA: Yes - please keep an eye on AMFX (HTTPChannel) tests.
    Doc: No
    Checkintests: Pass - except the usual 4-5 tests that time out on my machine.
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/rpc/src/mx/messaging/channels/amfx/AMFXDecoder.as

    Dear Pallavi,
    Very useful post!
    I am looking for similar accelerators for
    Software Inventory Accelerator
    Hardware Inventory Accelerator
    Interfaces Inventory
    Customization Assessment Accelerator
    Sizing Tool
    Which helps us to come up with the relevant Bill of Matetials for every area mentioned above, and the ones which I dont know...
    Request help on such accelerators... Any clues?
    Any reply, help is highly appreciated.
    Regards
    Manish Madhav

  • Parsing wildcard string similar to GREP

    I am building a tool and want to allow the user to type wildcard strings similar to what can be passed to the GREP application.  For example:
    c:\test\myfiles*.log
    Then my application would be able to parse this to retrieve an array of files that satisfy this path specification.  Ultimately I need to be able to read all of the matching files.
    Can someone please help?
    Thank you.

    And your question is...?
    (By the way, I generally use a StringTokenizer to do exactly that.)

  • Searching for certain string with wildcards

    Hi all,
      I am trying to find the characters  'GW' in material description with these examples:
      A)     (GW51) Metal spec round   --normally written this way
       B)     GW51) Metal spec round  -- typing error omit the left brackett
       C)     (GW51  Metal Spec round  --  typing error  omit the right brackett
       The codes works for A and C.
           FIND FIRST  OCCURENCE OF '(GW'  in material_desc.
       I am unable to use wildcards to find for GW*)  for B using FIND statement.
      Can anyone share with me using FIND for B ? 
    Thank you.
    Joyce

    use CP.
    if material_desc CP '*GW*'.
      write material_desc. " or do what ever you want.
    endif.

  • Using a variable in a Powershell search and replace string

    Hi
    a couple of days ago I posted a question about doing a search and replace with wildcards
    Search and repalce with Widcards
    I got a swift and very helpful answer but now I need to build on it.
    In a text file I wanted to replace all the text between two defined words.  the script I got was this
    $text = 'Some Server this bit of text varies Language stuff'
    $text -replace '(.*Server) .+? (Language.*)','$1 it will always say this $2'
    It works great but now I want to replace "it will always say this" with a variable and I can't figure out the correct grammar to make this happen.
    Can anyone help??
    Thanks
    Alex

    Here's one way:
    $replace = 'it will aways say this'if ( $text -match '(.*Server) .+? (Language.*)' )
    { "{0} $Replace {1}" -f $matches[1,2] }
    else { $text }
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Using wildcards in import statement

    I typically use wildcards in my import statements. For example:
    import javax.swing.*;
    Are there any advantages, though, in specifying exactly which classes I am importing?
    For example,
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JEditorPane;
    import java.swing.JProgressBar;
    // etc.
    Specigically, is the resulting class file any smaller if I specify exactly which classes to use and does the Java runtime engine load faster if I specify exactly which classes I use in the import statemetents?
    Thanks,

    Import has precisely zero runtime impact. I believe it is used to help locate the specified class at runtime. Take the following 2 simple source files:
    import java.util.Vector;
    //import java.util.*;
    public class VectorTest
         public static void main( String[] args )
              Vector v = new Vector();
              v.add("Item 1");
              v.add("Item 2");
              System.out.println( v.get(1) );
    public class Vector
         public boolean add(Object o)
              return true;
         public Object get(int index)
              return "doh!";
    }1) Run the code as is and "Item 2" is displayed
    2) Recompile the code using the generic import and "doh!" is displayed.
    The point is that by fully qualifying the import statement you are sure you are executing the correct class and not just some class that happens to be lying around somewhere in your classpath.

  • Find & replace part of a string in Numbers using do shell script in AppleScript

    Hello,
    I would like to set a search-pattern with a wildcard in Applescript to find - for example - the pattern 'Table 1::$*$4' for use in a 'Search & Replace script'
    The dollar signs '$' seem to be a bit of problem (refers to fixed values in Numbers & to variables in Shell ...)
    Could anyone hand me a solution to this problem?
    The end-goal - for now - would be to change the reference to a row-number in a lot of cells (number '4' in the pattern above should finally be replaced by 5, 6, 7, ...)
    Thx.

    Hi,
    Here's how to do that:
    try
        tell application "Numbers" to tell front document to tell active sheet
            tell (first table whose selection range's class is range)
                set sr to selection range
                set f to text returned of (display dialog "Find this in selected cells in Numbers " default answer "" with title "Find-Replace Step 1" buttons {"Cancel", "Next"})
                if f = "" then return
                set r to text returned of (display dialog "Replace '" & f & "' with " default answer f with title "Find-Replace Step 2")
                set {f, r} to my escapeForSED(f, r) -- escape some chars, create back reference for sed
                set tc to count cells of sr
                tell sr to repeat with i from 1 to tc
                    tell (cell i) to try
                        set oVal to formula
                        if oVal is not missing value then set value to (my find_replace(oVal, f, r))
                    end try
                end repeat
            end tell
        end tell
    on error number n
        if n = -128 then return
        display dialog "Did you select cells?" buttons {"cancel"} with title "Oops!"
    end try
    on find_replace(t, f, r)
        do shell script "/usr/bin/sed 's~" & f & "~" & r & "~g' <<< " & (quoted form of t)
    end find_replace
    on escapeForSED(f, r)
        set tid to text item delimiters
        set text item delimiters to "*" -- the wildcard 
        set tc1 to count (text items of f)
        set tc2 to count (text items of r)
        set text item delimiters to tid
        if (tc1 - tc2) < 0 then
            display alert "The number of wildcard in the replacement string must be equal or less than the number of wildcard in the search string."
            error -128
        end if
        -- escape search string, and create back reference for each wildcard (the wildcard is a dot in sed) --> \\(.\\)
        set f to do shell script "/usr/bin/sed -e 's/[]~$.^|[]/\\\\&/g;s/\\*/\\\\(.\\\\)/g' <<<" & quoted form of f
        -- escape the replacement string, Perl replace wildcard by two backslash and an incremented integer, to get  the back reference --> \\1 \\2
        return {f, (do shell script "/usr/bin/sed -e 's/[]~$.^|[]/\\\\&/g' | /usr/bin/perl -pe '$n=1;s/\\*/\"\\\\\" . $n++/ge'<<<" & (quoted form of r))}
    end escapeForSED
    For what you want to do, you must have the wildcard in the same position in both string. --> find "Table 1::$*$3", replace "Table 1::$*$4"
    Important, you can use no wildcard in both (the search string and the replacement string) or you can use any wildcard in the search string with no wildcard in the replacement string).
    But, the number of wildcard in the replacement string must be equal or less than the number of wildcard in the search string.

Maybe you are looking for

  • How to set up email on N86?

    I've tried several accounts, and no matter what I try the Nokia email setup gets stuck on "contacting email server". I would have thought it would work at least for gmail. The automated process doesn't let me put in any of the settings manually. God

  • Analytic function to retrieve a value one year ago

    Hello, I'm trying to find an analytic function to get a value on another row by looking on a date with Oracle 11gR2. I have a table with a date_id (truncated date), a flag and a measure. For each date, I have at least one row (sometimes 2), so it is

  • HT1338 Can you send IMovies to an external hard drive?

    How can I send all IMovies in my MacBook Air to be backed up in an external hard drive. Can someone send me a step by step procedure to follow please.

  • Post gong black strips with white type. System Failure: cpu=0;  etc. HELP

    I happened to plug in a palm pilot dock unit to my keyboard while my machine was booting up and although it may have noting to do with it, I now have the grey screen with the system failure message. The first line ends with "Corrupt Stack" and it goe

  • Help! iPad 2 showing NEF/RAW files as 'local disk' ?!

    Hi all. I really hope someone can help as this is doing my nut in! I've always used the camera connection kit with my iPad 2 and Nikon D700 before with no problems. I can transfer the RAW/NEF files from my camera to my iPad 2, and then when I get hom