Problem with my regular expression

Hi
I am trying to find function declarations within source code. I've been trying to use regular expressions, but if anyone else has an easier / better way to do this, as ross perot said, "I'm all ears"
Here's my regular expression printed out:
sb = [.]*void foo[.]*
sb is a stringbuffer variable, so the regex is [.]*void foo[.]*
Can anyone tell me why when I run this pattern on my loaded source file it tells me that the pattern does not match? LOL can you help me fix this?

I doubt that regex is a very good way to find method
declarations, although you can probably make it work
reasonably well for the most common cases.You've got a point. This is just to get the ball rolling. I don't want to have to do full syntax parsing yet.
>
In your particular situation, I'd guess it has to do
with [.]*. I think that inside [], the
dot is a literal dot, not "any character." If you
want "zero or more of anything followed by void" then
it's .*void.
Just tried
sb = .*void foo.*
it still didn't work.
In any case, however, this only covers methods
returning void. For the more general case, I don'tI didn't give you all my code. I actually use a classloader and reflection to determine what the methods are, return values etc. So yes, void in this case is not overly flexible, but I can plug in whatever it is I'm looking for.
think a simple regex will do it. You need a kind of
tool that I can't recall the name of--something to
build and examine an abstract syntax tree perhaps.
Try starting here:
http://www.google.com/search?q=java+abstract+syn
tax+treeI'm not even sure it abstract syntax tree is what you
want, but I think it's at least closer than regex.
There might be something that's a step or two earlier
in the compilation process that will give you what
you want.

Similar Messages

  • Problems with java regular expressions

    Hi everybody,
    Could someone please help me sort out an issue with Java regular expressions? I have been using regular expressions in Python for years and I cannot figure out how to do what I am trying to do in Java.
    For example, I have this code in java:
    import java.util.regex.*;
    String text = "abc";
              Pattern p = Pattern.compile("(a)b(c)");
              Matcher m = p.matcher(text);
    if (m.matches())
                   int count = m.groupCount();
                   System.out.println("Groups found " + String.valueOf(count) );
                   for (int i = 0; i < count; i++)
                        System.out.println("group " + String.valueOf(i) + " " + m.group(i));
    My expectation is that group 0 would capture "abc", group 1 - "a" and group 2 - "c". Yet, I I get this:
    Groups found 2
    group 0 abc
    group 1 a
    I have tried other patterns and input text but the issue remains the same: no matter what, I cannot capture any paranthesized expression found in the pattern except for the first one. I tried the same example with Jakarta Regexp 1.5 and that works without any problems, I get what I expect.
    I am using Java 1.5.0 on Mac OS X 10.4.
    Thank to all who can help.

    paulcw wrote:
    If the group count is X, then there are X plus one groups to go through: 0 for the whole match, then 1 through X for the individual groups.It does seem confusing that the designers chose to exclude the zero-group from group count, but the documentation is clear.
    Matcher.groupCount():
    Group zero denotes the entire pattern by convention. It is not included in this count.

  • Problem with email regular expression

    I found the following regular expression from this website : http://www.regular-expressions.info/email.html
    \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\bor
    ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$I am using the following website to check its success, as well as my java app. : http://www.regexplanet.com/simple/index.html
    of course java has a problem with the illegal escape character so i add another "/".
    In both of my testing scenarios the regex value seems to fail. Am I missing something here?
    If anyone could also test this regex and verify or correct my problem I would be very grateful.
    Edited by: rico16135 on Jun 5, 2010 4:01 PM
    Edited by: rico16135 on Jun 5, 2010 4:02 PM

    rico16135 wrote:
    of course java has a problem with the illegal escape character so i add another "/".I seem to be missing the distinction between a forward slash / which is not an escape character, and a backslash \ which is.
    Also, if you show your actual Java code (in code tags, of course), and describe clearly and precisely what's going wrong--pasting in the exact, complete error message and indicating clearly which line caused it, if there is one--people will be in a better position to help you.

  • Problem with java regular expression

    Hi,
    I try to use the regular expression as follows
    Pattern pattern = Pattern.compile("\wpub\w");
    Matcher matcher = null;
    matcher = pattern.matcher("38712pubeeqpwoiu");
    if (matcher.matches())
    System.out.println("Matched");
    else
    System.out.println("Not Matched");
    and I always get the answer as "Not Matched". I am not sure what is wrong with the code.
    thanks

    Use find() rather than matches().

  • Problem with a regular expression

    I want to check the date.
    I wrote a sample pattern
    pattern = Pattern.compile("([0-9]{2}\\.[0-9]{2}\\.[0-9]{2,4}){0,10}");DD.MM.YYYY
    DD.MM.YY
    "" - empty date
    It works fine, but how could I check, whether the date is not greater than 31 and so on with the other things.
    It should pass:
    "11.12.2006"
    "15.15.2005" - wrong date
    "01.00.2005" - worng date
    "22.22.1000" - also could be wrong.
    Thanks in advance.

    CalendarI check befor the data will be sent to the database.Good. I just meant that regex can't check whether Febuary has 28 or 30 days in a giant leap year.
    There is not only dates, special fields like names,
    ids and so on. I check all with regular expressions,
    wanted the date also. And wanted to know whether it
    is possible in this expression to make so, that the
    date can be "". I can check it explicitly, I wanted
    to do all the job with a regex.Why not simply check for a String length of 0? :)
    The first sample I wrote allows
    "DD.MM.YYYY" and "" and "DD.MM.YY", but in last
    sample "" and YY impossibleHm? You mean two-digit year and no year (but the rest of date still present)?

  • Little help with this regular expression ?

    Greetings all,
    My string is like "P: A104, P105, K106" and I tried to split it using following regular expression ,but seems even though it returns 'true' as matched, it does not split the string.
    Finally what I want is String is array like {"P:","A104","P105","K106"}
    What seems to be the problem with my regular expression?
           String PAT1="[a-zA-Z]:\\s([a-zA-Z]\\d{1,}([,]\\s)?)*";
         String inp="P: A104, P105, K106";
         Pattern p=Pattern.compile(PAT1);
         System.out.println(p.matcher(inp).matches());
         String strs[]=inp.split(PAT1);
         for(String s:strs){
              System.out.println("part  "+s);
         }

    pankajjaiswal10 wrote:
    You can also use split(":|,")No, that will remove the colon and leave the whitespace intact. My understanding is that the OP wants to keep the colon and remove the commas and whitespace. I would use this: String[] strs = inp.split(",?\\s+");

  • What's wrong with the regular expression?

    Hi all,
    For the life of me I can not figure out what is wrong with this regular expression
    .*\bA specific phrase\.\b.*
    This is just an example the actual phrase can be an specific phrase. My problem comes when the specific phrase ends in a period. I've escaped the period but it still gives me an error. The only time I don't get an error is when I take off the end boundry character which will not suffice as a solution. I need to be able to capture all the text before and after said phrase. If the phrase doesn't have a period it would look like this...
    .*\bA specific phrase\b.*
    which works fine. So what is it about the \.\b combination that is not matching?
    I've been banging my head on this for a while and I'm getting nowhere.
    The application highlights text that comes from a server. The user builds custom highlights that have some options. Highlight entire line, match partial word, and ignore case. The code that builds my pattern is here
    String strHighlight = _strHighlight;
            strHighlight = strHighlight.replaceAll("\\*", "\\\\*");
            strHighlight = strHighlight.replaceAll("\\.", "\\\\.");
            String strPattern = strHighlight;
            if(_bEntireParagraph)
                if(_bPartialWord)
                    strPattern = ".*" + strHighlight + ".*";
                else               
                    strPattern = ".*\\b" + strHighlight + "\\b.*";           
            else
                if(_bPartialWord)
                    strPattern = strHighlight;
                else               
                    strPattern = "\\b" + strHighlight + "\\b";  
            if(_bIgnoreCase)
                _patHighlight = Pattern.compile(strPattern, Pattern.CASE_INSENSITIVE);
            else
                _patHighlight = Pattern.compile(strPattern);So for example I matching the phrase: The dog ate the cat. And that phrase came over in the following text: Look there's a dog. The dog ate the cat. "Oh my!"
    And my user has the entire line and ignore case options selected then my regex woud look like this: .*\bThe dog ate the cat\b.*
    That should get highlighted, but for some reason it doesn't. Correct me if I'm wrong but doesn't the regex read as follows:
    any characters
    word boundry
    The dog ate the cat[period]
    word boundry
    any characters until newline.
    Any help will be much appreciated

    A word boundary (in the context of regexes) is a position that is either followed by a word character and not preceded by one (start of word) or preceded by a word character and not followed by one (end of word). A word character is defined as a letter, a digit, or an underscore. Since a period is not a word character, the only way the position following it could be a word boundary is if the next character is a letter, digit or underscore. But a sentence-ending period is always followed by whitespace, if anything, so it makes no sense to look for a word boundary there. I think, instead of \b, you should use negative lookarounds, like so:   strPattern = ".*(?<!\\w)" + strHighlight + "(?!\\w).*";

  • Hello i have a problem with my airport express the music sizzles? Why?

    Hello i have a problem with my airport express the music sizzles? Why?
    What can i do?

    Does the game has the same iOS requirements that your phone has? Games needing iOS7 will not install on iOS6 and earlier.
    Did you try to download it to your computer and sync it to your phone after that?
    If you can't connect to the iTunes Store, try these suggestions:
    Can't connect to the iTunes Store

  • Chroma Key problems with Final Cut Express 4

    I had no problems with the Chroma Key in Final Cut Express 4 before. It was working perfectly fine untill I brought anther Macbook Pro last year in August. I installed it on the new computer and then the Chroma Key didn't work. Final Cut opens up and the other filters work fine but I can't get the chroma key to work. Any possible reasons?

    I am experiencing an interseting problem with Final Cut Express on OSX Lion.  I teach in a Mac Lab at my school.  Today I was trying to teach Chroma Keying- which I have been doing for years - but for some reason the color selector would just not key out anything.   I tried it on four or five different machines, and it turns out that ONLY my machines that were running OSX Leopard would allow the Chroma Key to function.  I have two machines running Lion and the Chroma Key would not work on EITHER of them.  I followed the exact same steps, and all of the settings were identical.  The hardware was also the exact same package from machine to machine.  I feel like there must be an issue with OSX Lion that is breaking the Chroma Key filter.  Can anyone help?

  • Problem with a regular expresion,for Scanner delimiter

    Hi,I'm having a problem I have a the following example text
    This is a simple #test with #lots of #sharps and normal text just for #testing #a #regular expression.
    also I have this regular expresion \\w*#\\w*
    the problem is that this regular expression as a delimiter in a Scanner class will read/parse only the words that dont have a +#+ as first char, the problem is that i need the exact opposite , i need to parse/read only the words that have a +#+ as first char.
    Thanks in advance.

    What you're trying to do is the opposite of what a Scanner is usually used for, but that's okay, because Scanner provides methods for that, too: Scanner sc = new Scanner(yourFile);
    String token = null;
    while ((token = sc.findWithinHorizon("#\\w+", 0) != null)
      System.out.println(token);
    } Passing zero as the second parameter means no horizon, i.e., find the next match no matter how far along it is. If you want to limit the search to the current line, you can use findInLine().

  • Parse Mac Address with match regular expression

    Hi Everyone,
    I have a problem with the Match Regular Expression function,
    I am trying to parse the response two a arp -a 192.168.0.15 request in order to extract MAC address of this remote IP, I used the following RegEx: ^([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$
    I am wondering why do I need to do a string subset first to extract only the MAC Address part. Isn't Match Regular Expression function capable of recognizing the RegEx directly in the middle of a string?
    I only works when I extract the right tring subset as in the picture bellow.
    Thanks for your answers.
    Solved!
    Go to Solution.
    Attachments:
    Mac Address.JPG ‏40 KB

    Get rid of the "^" in the beginning of your regular expression. You are instructing it to find the pattern at the beginning of the string.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • I have a problem with oracle 10g express edition

    Hello,
    I have just installed oracle 10g express edition and I have a problem with the script editor. I can write anything in the window that appears below buttons undo,redo and find, It is like disabled. I use windows XP, Firefox 2.0 ( I have also tried with Iexplorer and It does not work either). I have javascript enabled.
    anyone knows what is the problem?
    Later,I have installed it in a virtual machine of Windows 2003 Server and It works well but I`d rather use it in my Microsoft XP
    Thank you very much
    Fernando Martínez

    It looks like you can fix this if you replace the codearea.xbl.xml and codearea.iframe.html files in the
    /i/editor folder with files from an Apex 2.2.1 installation - such as the one on apex.oracle.com.
    Since I don't know what the licensing implications are, I will let you figure out the details.

  • Help with java regular expressions

    Hi all ,
    i am going to match a patternstring against an input string and print the result here is my code:
         import java.util.regex.*;
         import java.util.*;
         public class Main {
              private static final String CASE_INSENSITIVE = null;
              public static void main(String[] args)
              CharSequence inputStr = "i have 5 years FMCG saLEs exp on java/j2ee and i worked on java and j2ee and 2 projects on telecom java j2ee domain with your  with saLEs maNAger experience of java j2ee and c# having very good  on c++ exposure in JAVA"
             String patternStr = "\"java j2ee\" and \"c#\"";
              StringTokenizer st = new StringTokenizer(patternStr,"\",OR");
             Matcher matcher=null;
              while(st.hasMoreTokens()){
                   String s=st.nextToken();
                   Pattern pattern = Pattern.compile(s,Pattern.CASE_INSENSITIVE);
               matcher = pattern.matcher(inputStr);
               while (matcher.find()) {
                  String result = matcher.group();
                 if(!result.equalsIgnoreCase(" "))
                             System.out.println("result:"+result);
         when i compile this code i am getting the expected result...ie
    result:java j2ee
    result:java j2ee
    result: and
    result: and
    result: and
    result: and
    result: and
    result: and
    result:c#
    but when i replace String patternStr = "\"java j2ee\" and \"c#\""; with
    String patternStr = "\"java j2ee\" and \"c++\""; i am just getting c in the result instead of c++ ie i am getting result :
    result:java j2ee
    result:java j2ee
    result: and
    result: and
    result: and
    result: and
    result: and
    result: and
    result:C
    result:c
    result:c
    result:c
    result:c
    result:c
    result:c
    In the last lines i should get result:c++ instead of result: c
    Any ideas please
    Thanks

    In the last lines i should get result:c++ instead of result: cThe regular expression parser considers the plus sign '+' a special
    character; it means: one or more times the previous regular expression.
    So 'c++' means one or more 'c's on or more times. Obviously you don't
    want that, you want a literal '+' plus sign. You can do that by prepending
    the '+' with a backslash '\'. Unfortunately, the javac compiler considers
    a backslash a special character and therefore you have to 'escape'
    the backslash also, by adding another backslash. The result looks
    like this:"c\\+\\+"kind regards,
    Jos

  • Problem with launching 10g express edition

    Hi, i am from Czech Republic and i have big problem with launching Oracle database 10g Express Edition.
    After instal program i launch "Go to Database Home Page" and IE write to me "Page not found" (web adress is http://127.0.0.1:8080/apex).
    Please,can anyone help me what i have to do to launch it correctly?
    Thank you.
    Message was edited by:
    user628210
    Message was edited by:
    user628210

    hi again. first a have to apologize. i have oracle
    database express edition 10g from school,so i dont
    have registered version.When I said 'register' I didn't mean have it licensed, Oracle XE doesn't require any kind of license registration, it is free. By registering it I meant a technical issue. Once the database is started it tries to contact the listener at 1521 port, once contacted the oracle instance registers itself against it, and if it is successful you will have the administrator's page initialized and ready to access at the default 8080 port.
    when i type SQL commands, command line wrote me
    SP2-0734:unknown command beginning ENTERED COMMAND
    Could you please specify which command did you try to enter?
    >
    and when i open RUN DATABASE, command line wrote
    C:\OracleDatabase\app\oracle\product\10.2.0\server\BIN
    net started OracleServiceXE - system error 5, accessdenied
    What do you mean with 'RUN DATABASE'?
    ~ Madrid
    http://hrivera99.blogspot.com/

  • Help with Understanding Regular Expressions

    Hello Folks,
    I need some help in understanding the Regular Expressions.
    -- This returns the Expected string from the Source String. ", Redwood Shores,"
    SELECT
      REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA,aa',
                    ',[^,]+,', 1, 1) "REGEXPR_SUBSTR"
      FROM DUAL;
    REGEXPR_SUBSTR
    , Redwood Shores,
    However, when the query is changed to find the Second Occurrence of the Pattern, it does not match any. IMV, it should return ", CA,"
    SELECT
      REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA,aa',
                    ',[^,]+,', 1, *2*) "REGEXPR_SUBSTR"
      FROM DUAL;
    REGEXPR_SUBSTR
    NULLCan somebody help me in understanding Why Second Query not returning ", CA,"?
    I did search this forum and found link to thread "https://forums.oracle.com/forums/thread.jspa?threadID=2400143" for basic tutorials.
    Regards,
    P.

    PurveshK wrote:
    Can somebody help me in understanding Why Second Query not returning ", CA,"?With your query...
    SELECT
      REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA,aa',
                    ',[^,]+,', 1, *2*) "REGEXPR_SUBSTR"
      FROM DUAL;You are looking for patterns of "comma followed by 1 or more non-comma chrs followed by a comma."
    So, let's manually pattern match that...
    '500 Oracle Parkway, Redwood Shores, CA,aa'
                       ^               ^
                       |               |
                               |
                               |
                      Here to here is the
                      first occurence.So the second occurance will start searching for the same pattern AFTER the first occurence.
    '500 Oracle Parkway, Redwood Shores, CA,aa'
                                        ^
                                        |
    i.e. the search for the second occurence starts heretherefore the first "," from that point is...
    '500 Oracle Parkway, Redwood Shores, CA,aa'
                                           ^
                                           |
                                          hereand there is nothing there matching the pattern you are looking for because it only has the
    "comma follwed by 1 or more non-comma chrs"... but it doesn't have the "followed by a comma"
    ...so there is no second occurence,

Maybe you are looking for

  • Output report data to excel file format or csv format

    Is there any way to save softcopy of report output to excel file format or csv format.

  • Title Box sticks until quit

    iPhoto '08 (version 7.1.5 (378)) on a PPC (1.6 Ghz Dual G4 with 1.38 GB RAM) OS 10.4.11 When you're in iPhoto viewing "all photos" as opposed to viewing as Events, you get a large grey transparent box in the middle of the window which contains the da

  • What happens when the Flex 2 builder trial expires?

    Here in South Africa bandwidth is quite expensive and I would like to know if I can still use Eclipse for other purposes after the Flex 2 builder trial has expired. If it totally disables Eclipse it means that I have to download the standard version

  • Set focus on cell in ATS Table

    Hi Friends, I try to set the focus on a field in a if_fpm_guibb_list. I use Methode request_focus_on_cell in if_fpm_list_ats_ext_ctrl. And I set lead Index to new line and set selected_line _changes to 'X'. When I look in the table what contain the n

  • Where would I downlaod Jrockit 1.6.0_37 from on oracle site ??

    from where would I downlaod Jrockit 1.6.0_37 as I am hitting the bug mentioned in Error Occurred While creating OPSS Security Store in OIM 11.1.2.1 Install [ID 1555444.1] Error Occurred While creating OPSS Security Store in OIM 11.1.2.1 Install [ID 1