Regex error

Discussion in 'Java' started by DemmeGod, May 26, 2004.

  1. DemmeGod

    DemmeGod Guest

    Does anyone know why the following regex:
    class \S*|\S* \S*\([^;]*\)\s*{

    Gives me this exception:
    java.util.regex.PatternSyntaxException: Illegal repetition near index 28

    Index 28 is the 's' in "\s". I'm just trying to allow for whitespace.

    Thanks
     
    DemmeGod, May 26, 2004
    #1
    1. Advertising

  2. DemmeGod

    Alan Moore Guest

    On 25 May 2004 23:01:17 -0700, (DemmeGod) wrote:

    >Does anyone know why the following regex:
    >class \S*|\S* \S*\([^;]*\)\s*{
    >
    >Gives me this exception:
    >java.util.regex.PatternSyntaxException: Illegal repetition near index 28
    >
    >Index 28 is the 's' in "\s". I'm just trying to allow for whitespace.
    >
    >Thanks


    The problem has to be the open brace at the end. If you don't escape
    it like you did the parentheses, the compiler expects to see a {m,n}
    type quantifier. By my count, that's index 29; looks like the
    compiler miscounted.
     
    Alan Moore, May 27, 2004
    #2
    1. Advertising

  3. DemmeGod

    DemmeGod Guest

    Gotcha... The test regex engine I ran it through detected there was no
    closing brace and ignored it as a special character.

    Alan Moore <> wrote in message news:<>...
    > On 25 May 2004 23:01:17 -0700, (DemmeGod) wrote:
    >
    > >Does anyone know why the following regex:
    > >class \S*|\S* \S*\([^;]*\)\s*{
    > >
    > >Gives me this exception:
    > >java.util.regex.PatternSyntaxException: Illegal repetition near index 28
    > >
    > >Index 28 is the 's' in "\s". I'm just trying to allow for whitespace.
    > >
    > >Thanks

    >
    > The problem has to be the open brace at the end. If you don't escape
    > it like you did the parentheses, the compiler expects to see a {m,n}
    > type quantifier. By my count, that's index 29; looks like the
    > compiler miscounted.
     
    DemmeGod, May 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    749
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,695
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    631
  4. Xah Lee
    Replies:
    1
    Views:
    976
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    835
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page