Regex error

D

DemmeGod

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
 
A

Alan Moore

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.
 
D

DemmeGod

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

Alan Moore said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top