Need suggestion to build a  Regular Expression

Hi,
I am trying to build a regex pattern to search a chunk of text.
The criteria of searching is something like as follows:
Lets us say i need to search for a string "Number". Here I should be
able find all the possible strings that closely resemble the string "Number".
i,e I should be able pick all the string like
" umber" , "N$mber", " ber", "Num ", "Nu,,er" ..........
Can anyone suggest me a strategy to build a pattern for this.
Thanks in advance,
Pavan Kumar

Thank you very much for suggestion and letting meknow that "it's impossible".
It is impossible if you come here and ask us to do it
for you. We will greatly help you if you provide us a
piece of mind that show you tried something.
Hire a programmer if you can't do it by yourself and
/or you don't want to learn how...I think he meant that its impossible because what the OP specified is not a regular language. Which is true in a sense, but since the OP's language is finite, it is a regular language. However, to do this with regexes you will find that you're fighting the language. I would implement that distance metric, as Tim suggested.

Similar Messages

  • Need Suggestion to build a simple web service demo

    I'm planning to build a demo using java packages JAX* for my team using my workstation and another standalone box.
    I got a Sun One Web Services Platform DVD from JavaOne, but it only support Win200 or XP, too bad our company still using Win NT SP6.
    I only need a very simple web service that will bring data from server DB. I knew I can download the JWSDP1.2, but there is no tutorial right now. And I have tried JWSDP1.1 but not really understand what it is doing(because only Hello world service is working). I need to do some modification to change the default server port from 80 to 81, and I need to modified localhost to [my-machine-name] so that the other machine can talk to the JWSDP server.
    My question is how can I build up a web service demo really easy and quick and what tool should I used, any suggestion will be appreciated! Thanks in advance!
    Henry

    1. Use XML Spy Enterprise edition editor.
    2. Goto www.xmethods.com, select service you want to create demo of.
    3. Get its WSDL url.
    4. In XML Spy SOAP menu there is a command 'create new soap request'. Press that, enter the WSDL url. You will get a SOAP request.
    5. Edit SOAP request parameters. Type parameters of your choice.
    6. Press 'send request to server'. You will get SOAP response. It will contain result from the requested method.
    7. Paste that response inside a JSP.
    8. Write a local method which will return same response (remote method's return value) that came from remote web service.
    9. Paste that method inside abovementioned JSP. Replace static response in that JSP with the response generated by local method. The method parameters will come from client's SOAP request. Parse SOAP request to get request parameters. (As it's your demo, you know the data types of the parameters).
    10. Host that JSP on any Servlet/JSP engine.
    That makes your Web Service.
    You can use any package like Aapche SOAP, AXIS or JAX-RPC to generate a SOAP client. Use the URL of JSP(step 10) as "endpoint".
    Note: Indside JSP make sure that there in no endline and carriage return character. Otherwise it won't be a valid SOAP response.
    Good luck.

  • How to build regular expression

    I am trying to build a regular expression that will search the following array of strings for the sequence 3.1
    Read Modem Information:
    Device Type .......................... 2
    Serial Number ........................ 11437
    Primary Phone Number ................. 1800...
    Secondary Phone Number ............... 1800...
    Modem Software ....................... BOOT.3.1 Jun 17 2004 17:02:26
    Bracelet Software .................... 4.0
    Validation Number .................... Default
    Login Name ........................... Default
    Login Password ....................... Default
    Case Number .......................... Default
    Primary Encryption Key ............... Default        
    Secondary Encryption Key ............. Default        
    Dialing Format ....................... True
    Call In Format ....................... True
    Modem Download Flag is Clear ......... True
    SCRAM Download Flag is Clear ......... True
    SCRAM Char Table Load Flag is Clear .. True
    Download Inhibit ..................... True
    Exiting Boot (8 sec) ................. Switching to operating memory.
    Main Revision ........................ SLCP.3.1 Jun 17 2004 17:02:46
    Reset ................................ Complete
    This is my first real foray into regular expressions and so I am lost trying to understand the help file.
    Thanks!
    Tay
    Message Edited by slipstick on 09-25-2008 09:34 AM

    I think the OP was puzzled about how to form a RE.
    For the specific case or how to find the exact string "3.1", and to not match anything else, the RE is "3\.1"
    Why?
    For the most part, a RE search string is an exact character match. However things change when certain "special characters" are included in the search string. The RE help message says what they are, but the descriptions can be a bit daunting at first.
    As a first example of special characters, the RE of "." (The single character fullstop) will match ANY single character. Thus a RE of "3.1" will match "3.1", "301", "3Z1", but not "31" or 3aa1".
    Another special character is "*". It modifies the match to allow zero or more of the preceeding bit. So "3.*1" matches "3", followed by any number of any character (including no characters), followed by "1". so it will match "31", "301", "3ABC51", "31111111"
    The action of a special character is cancelled by preceeding it with a backslash. So in the example above "3\.1" matches ONLY the string "3.1"
    The best way to discover exactly how RE's work is to try some out. Make a VI containing Match Pattern, and suitable controls and indicators. Work through the examples and see how they operate. Now try your own!

  • Regular expression question (should be an easy one...)

    i'm using java to build a parser. im getting an expression, which i split on a white-space.
    how can i build a regular-expression that will enable me to split only on unquoted space? example:
    for the expression:
    (X=33 AND Y=44) OR (Z="hello world" AND T=2)
    I will get the following values split:
    (X=33
    AND
    Y=34)
    OR
    (Z="hello world"
    AND
    T=2)
    and not:
    (Z="
    hello
    world"
    thank you very much!

    Instead of splitting on whitespace to get a list of tokens, use Matcher.find() to match the tokens themselves: import java.util.*;
    import java.util.regex.*;
    public class Test
      public static void main(String[] args) throws Exception
        String str = "(X=33 AND Y=44) OR (Z=\"hello world\" AND T=2)";
        List<String> tokens = new ArrayList<String>();
        Matcher m = Pattern.compile("[^\\s\"]+(?:\".*?\")?").matcher(str);
        while (m.find())
          tokens.add(m.group());
        System.out.println(tokens);
    }{code} The regex I used is based on the assumptions that there will be at most one run of quoted text per token, that it will always appear in the right hand side of an expression, and that the closing quote will always mark the end of the token.  If the rules are more complicated (as sabre150 suggested), a more complicated regex will be needed.  You might be better off doing the parsing the old-fashioned way, with out regexes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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 expression html parsing

    I have following sample html
    <html><body>
    First Name<input type="text" class="txtField" name="txtFirstName"\>
    Last name
    <input type="text" name="txtLastName"\>
    Address <textarea name="address" rows="10">Here goes address</textarea>
    <input type="button" name="btnSubmit" class="button"\>
    </body></html>
    I m trying to build a regular expression in such a way that, the expression should find a list of tags based on the set of names available.
    for e.g. I have string array as String names[] = {"txtLastName", "address"}
    using above array, the expression must find tag in above html.
    So in above case the output should be
    <input type="text" name="txtLastName"\>
    <textarea name="address" rows="10">
    Can somebody suggest how this expression should be build?

    Hi,
    As from your question,
    I got that you want to parse the HTML file and from the names in the array you want to
    get the code those controls.
    In that case I think you can use
    Find the string
    1.which starts with '<' and ends with '>'
    2.It must contains your work("txtLastName", "address"....) in double quotes(statring & ending) excatly one.
    Best,
    Ronak

  • Regular Expression: Why does it select too much at beginning?

    I am trying to select some tags throughout XML files but the following pattern is selecting from the very first literal of "<DOMSymbolInstance"
    Pattern
    <DOMSymbolInstance[\]\w\t\n\r !"#$%&'()*+,./:;<=>?@[\\`{|}~^\-]+?<AS_OnButton_1/>
    String
                <DOMFrame index="0" keyMode="9728">
                  <elements>
                    <DOMSymbolInstance libraryItemName="DMC-Crimper/Side-A/PinSizeBtn" symbolType="button">
                      <matrix>
                        <Matrix a="1.35110473632813" d="1.35110473632813" tx="0.7" ty="0.8"/>
                      </matrix>
                      <transformationPoint>
                        <Point x="24.9" y="25.2"/>
                      </transformationPoint>
                      <AS_OnButton_0/>
                    </DOMSymbolInstance>
                  </elements>
                </DOMFrame>
                <DOMFrame index="1" duration="8" keyMode="9728">
                  <elements/>
                </DOMFrame>
                <DOMFrame index="9" keyMode="9728">
                  <elements>
                    <DOMSymbolInstance libraryItemName="DMC-Crimper/Side-A/PinSizeBtn" name="instanceNameAlreadyExisted_1_btn" symbolType="button">
                      <matrix>
                        <Matrix a="1.35110473632813" d="1.35110473632813" tx="0.7" ty="0.8"/>
                      </matrix>
                      <transformationPoint>
                        <Point x="24.9" y="25.2"/>
                      </transformationPoint>
                      <AS_OnButton_1/>
                    </DOMSymbolInstance>
                  </elements>
                </DOMFrame>
    I need the pattern to select the "<DOMSymbolInstance" that is immediately before the "<AS_OnButton_1/>", and not the very first  "<DOMSymbolInstance" in the string.
    Does anyone have any suggestions?

    I suggest you dump using regular expressions for extracting data from xml files. There are standard APIs that everyone uses for such tasks. Regular expressions are a bad idea for xml documents. Search Google for 'Java XML Parser' to read up on them.  Also, XML documents get very complicated to read with regular expressions due to what their xml schemas say are valid variations of valid XML documents, such as being able to ignore comments in the document.
    I believe this link may help:  http://www.w3schools.com/xpath

  • Pattern and Matcher of Regular Expressions

    Hello All,
    MTMISRVLGLIRDQAISTTFGANAVTDAFWVAFRIPNFLRRLFAEGSFATAFVPVFTEVK
    ETRPHADLRELMARVSGTLGGMLLLITALGLIFTPQLAAVFSDGAATNPEKYGLLVDLLR
    LTFPFLLFVSLTALAGGALNSFQRFAIPALTPVILNLCMIAGALWLAPRLEVPILALGWA
    VLVAGALQLLFQLPALKGIDLLTLPRWGWNHPDVRKVLTLMIPTLFGSSIAQINLMLDTV
    IAARLADGSQSWLSLADRFLELPLGVFGVALGTVILPALARHHVKTDRSAFSGALDWGFR
    TTLLIAMPAMLGLLLLAEPLVATLFQYRQFTAFDTRMTAMSVYGLSFGLPAYAMLKVLLP
    I need some help with the regular expressions in java.
    I have encountered a problem on how to retrieve two strings with Pattern and Matcher.
    I have written this code to match one substring"MTMISRVLGLIRDQ", but I want to match multiple substrings in a string.
    Pattern findstring = Pattern.compile("MTMISRVLGLIRDQ");
    Matcher m = findstring.matcher(S);
    while (m.find())
    outputStream.println("Selected Sequence \"" + m.group() +
    "\" starting at index " + m.start() +
    " and ending at index " m.end() ".");
    Any help would be appreciated.

    Double post: http://forum.java.sun.com/thread.jspa?threadID=726158&tstart=0

  • Regular expression fro date time format

    Hi
    im trying to use regexp_like() function in my where clause as
    select 1 from dual where REGEXP_LIKE(''31/12/2003 11:59:59 PM',regular expr pattern)
    I tried this pattern using the following regular expresion which i found on a web site. but this didnt work.
    '^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))(\/)(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M)?)|([01]\d|2[0-3])(:[0-5]\d){1,2})?$'
    can some one suggest me an alternative regular expression for this.
    P.S : i donot want to use to_char/ to_date functions.
    Regards
    Vibhuti

    Hi elic
    I tried with your suggestion yet it didnt work. This is my query
    select 1 from dual where regexp_like('03/02/2000 02:59:59 AM','^(?=[0-9])(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9][0-9])?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?: |$))|(?:2[0-8]|1[0-9]|0?[1-9]))(\/)(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9][0-9])?[0-9][0-9](?:(?= [0-9]) |$))?(((0?[1-9]|1[012])(:[0-5][0-9]){0,2}( [AP]M)?)|([01][0-9]|2[0-3])(:[0-5][0-9]){1,2})?$')
    this should return 1 as output. but its not returning any thing. Im currently working on 10g R2 database. Please help me out, its very critical. Im trying to learn regualr expressions but im unable to crack this code.
    Regards
    Vibhuti

  • Regular Expressions

    I am trying to use a regular expression to filter out certain urls from getting aliased in my httpd.conf file.
    I currently have
    ScriptAliasMatch /someDir/ "C:/myCGIBin/"
    which redirects any urls starting with someDir.
    Ex. http://www.mySite.com/someDir/someApp.exe maps internally to c:/myCgiBin/someApp.exe
    The catch is that there is 1 subdirectory which should not point to the cgi-bin
    /someDir/specialDir/*
    So any requests to this special directory should fail the ScriptAliasMatch, while all others pass.
    ex.
    /someDir/somefile.exe PASS
    /someDir/someOtherDir/* PASS
    /someDir/specialDir/* FAILI am not sure how to build a regular expression to achieve this.

      public static void test3() {
        // (?!XXXXX) is negative look ahead,
        // so the regex does not match XXXXX right after /dirA/
        String str = "/dirA/(?!dirB/).*";
        Pattern pat = Pattern.compile(str);
        String [] testCases = { "/dirA/file.exe",
                                "/dirA/goodDir/*",
                                "/dirA/dirB/*",
                                "/dirA/dirB.txt"}; // this last one is valid!
        Matcher m = pat.matcher("");
        for (int i = 0, maxi = testCases.length; i < maxi; i++)
            m.reset(testCases);
    System.out.println(testCases[i] + " passes: " + m.find());

  • Regular expression problem?

    Hi I have a file which contains the following text
    <cfset objNews.strNewsTickerLink =
    "index.cfm?pageid=83">
    Now what i'd like to do is to scrape out the value of this
    variable i.e. 'index.cfm?pageid=83'. Now this variable can be
    different.... so basically whatever the value of the variable
    objNews.strNewsTickerLink is set to.. I'd like to get it out. Now
    I'm not that great with regular expressions... can anyone help me
    out?
    Thx

    Hi,
    One way of handling that is to use this UDF,
    http://cflib.org/udf/queryStringGetVar
    But, you must be aware of the url variable that comes after
    "?" symbol in order to use the above udf. If it is dynamically
    generated you need to write your own regular expression.
    HTH

  • Regular Expression ambiguous

    I know the purpose of that code , but I don't understand it Sad
    SQL> SELECT REGEXP_SUBSTR(
    'The final test is is the implementation',
    '([[:alnum:]]+)([[:space:]]+)\1') AS substr
    FROM dual;
    SUBST
    is is
    I study Regular Expression nowadays , from that link :-
    http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/rischert_regexp_pt1.html
    but I'm still need more good resources for ( Regular Expression white paper ) until I can understand all benefits , hence I can take Full Control of it.

    just one thing to be aware of unrelated to backreferencing:
    that Regex is less than perfect for the purposes of matching multiple words together:
    SELECT REGEXP_SUBSTR(
    'The diagram is isometric',
    '([[:alnum:]]+)([[:space:]]+)\1') AS substr
    FROM dual;so perhaps something like this:
    SELECT REGEXP_SUBSTR(
    'The diagram is isometric and and in pencil',
    '([[:alnum:]]+)([[:space:]]+)\1\2') AS substr
    FROM dual;using the backreference again to find the same space after the second word
    but then again, this doesn't work perfectly because what if there's only one space after the second word but two after the first... and what if the duplicate word is at the end of the string without any other characters after it at all!!!!
    find someone who can write a perfect regex and you'll have found someone who has too much time on their hands... :-P

  • Regular Expression/Challange

    i need to creat a little regular expression here are the conditions, I know i looks weired but this is what i need.
    Anyhelp will be appreciated
    First, i need to find 35 consecutive zeros(00000000000000000000000000000000000) from a text file and they could be more than one place. If i find them i need 9th 10th and 11th position value and then put a space then i need 16th and 17th position value and then a space and then 18th and 19th position value and then put a space and then those 35 zeros.
    Example
    1113578122211112233000000000000000000000000000000000000
    Output should be
    222 22 33 00000000000000000000000000000000000
    I hope this makes sense

    Text in c:/myfile.txt
    1860000000000000000000002220000334492378000000000000000000000000000000000005209673230000000000000000000000000000000004400000000000000000000000000000000000
    19287350000000000000000000000000000000000099200287450000000000000000000000000000000000000
    417782000000000000000000000000000000000009255566
    (I added these underline to explain it to you please take these underline off when you are actually running the program)
    OUTPUT
    Enter file name for search: c:/myfile.txt (+you provide the file name and location+)
    033449237800000000000000000000000000000000000
    000000004400000000000000000000000000000000000
    992002874500000000000000000000000000000000000
    Total occurance of 35 Consecutive zeros in the file is: 3
    This is the code that i have
    import java.util.regex.*;
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.charset.*;
    public class thirtyfivezeros
    public static void main(String[] args) throws IOException
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter file name for search: ");
    String filename = in.readLine();
    File file = new File(filename);
    if(!filename.endsWith(".txt")){
    System.out.println("This is not a text file.");
    System.out.println("Please enter file name withe \".txt\" extension.");
    System.exit(0);
    else if(!file.exists()){
    System.out.println("File not found.");
    System.exit(0);
    FileChannel fileChannel = new FileInputStream(filename).getChannel();
    CharBuffer charBuffer = Charset.forName("8859_1").newDecoder().decode(
    fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)fileChannel.size()));
    Pattern pattern = Pattern.compile("([0-9]{10})0{35}");
    Matcher matcher = pattern.matcher(charBuffer);
    int a = 0;
    while(matcher.find())
    String matchStrings = matcher.group();
    FileWriter fstream = new FileWriter("c:/bhayo.txt",true);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(matchStrings);
    out.newLine();
    System.out.println(matchStrings);
    a++;
    out.close();
    System.out.println("Total occurance of 35 Consecutive zeros in the file is: " + a);
    PROBLEM_
    I wanted the following output ( )
    222 33 44 00000000000000000000000000000000000 ( remember i have space in between 222 ,33 and 44 and the zeros) instead of like what i have in output (033449237800000000000000000000000000000000000)
    (I am counting from right to left, Starting from first 4 (left to the first zero of consecutive 35 zeros))
    44 are the 1st and second numbers
    33 are 3rd and fourth numbers
    222 are 9th 10th and 11th numbers
    Is there a regular expression that could help me format myfile.txt the way i mentioned above.
    I really appreciate you taking time to help me out.
    Hiklior

  • Regular Expression Pattern

    I currently have a RegExp pattern set up with the expression (\w\s\!\$/\(\)\&\.\+\-]+) (there is a [ between the ( and \w but it was showing HTML: instead of [ (maybe the problem?)) but when I try to compile the page, I get an XML-20201: (Fatal Error) Expected name instead of \ error
    Does anybody have any idea what I need to change in the regular expression to get it to run in Jdeveloper?
    Thanks
    Andy

    <messageTextInput id="${bindings.ItemCodesCodeDescription.path}" model="${bindings.ItemCodesCodeDescription}" required="yes" readOnly="${jhsUserRoles['ITEMS_RO']}" promptAndAccessKey ="Des&amp;cription" rows="1" maximumLength="50" columns="30">
    <onSubmitValidater>
    <regExp pattern="(\w\s\!\$/\(\)\&\.\+\-]+)"/> //again, [ between ( and \w
    </onSubmitValidater>
    </messageTextInput>
    It's part of a Description textInput, we want to limit the use of characters because it will be saved to our database

  • One question about Regular Expression!!!

    I need to creat such a regular expression to match the format "[ ][ ][ ]".
    For example, there is a context,
    (1), " The project manager defines [1][0.400][+goals] for iterations."
    Suppose that there are some spaces or "\n" characters in this way,
    (2), " The project manager defines [    1 ] [  0.400   ]
    [   +goals] for iterations."
    If the pattern match the format succefully, (2) strings should be replaced by (1)strings, in order words, the format of (1) is what I need finally,
    I had ever tried creating a regular expression likes \\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\] , but it does not work well!
    DO YOU HOW TO IMPLEMENT IT IN JAVA?
    Thanks for your any reply!

    What I really need is that, via the regular
    expression, all the spaces and \n characters in
    square brackets [ and ], ] and [, will be thrown
    away.
    For example,
    Original:
    1) "The project manager defines [   1  ] [
    0.400 ]
    [   +goals] for iterations with the support"
    After matching:
    2) "The project manager defines [1][0.400][ [+goals]
    for iterations with the support"
    String 2) is what I need finally!
    Thanks for your any reply!Well I gave you the answer to that one already :-)
    If you need to preserve the spaces in between words use this one. I'm sure there's a better way to do it, I'm no RegEx master.
        public static void main(String[] args)
            String s = "[ 1 ] [ 0.400 ]\n[ +go als]";
            System.out.println( "Before: " + s );
            System.out.println( "\n\n" );
            s = s.replaceAll( "\\[\\s+", "[" );
            s = s.replaceAll( "\\s+\\]", "]" );
            s = s.replaceAll( "\\]\\s+\\[", "][" );
            System.out.println( "After: " + s );
        }

Maybe you are looking for