Regexp help

M

mike

Hi,

I have the following line that I want to use a regexp to match:

I have tried the following pattern.

String pattern = "#define\\s[A-Z_]+\\s\\(\\"[A-Z_]+\\"\\)";

This is the input line that I want to match:

#define MY_NAME_INTERFACE ("GROUP_INTERFACE_04")

MY_NAME_INTERFACE - can contain any caps and underscore.
GROUP_INTERFACE_04 - can contain any caps and underscore as well as
digits at the end.

br,

//mike
 
J

Jussi Piitulainen

mike said:
Hi,

I have the following line that I want to use a regexp to match:

I have tried the following pattern.

String pattern = "#define\\s[A-Z_]+\\s\\(\\"[A-Z_]+\\"\\)";

This is the input line that I want to match:

#define MY_NAME_INTERFACE ("GROUP_INTERFACE_04")

MY_NAME_INTERFACE - can contain any caps and underscore.
GROUP_INTERFACE_04 - can contain any caps and underscore as well as
digits at the end.

You forgot the digits in your pattern.

Use just "\"" to put a quote in a string, and do not try to protect it
from interpretation by the regexp engine at all. It is not special.
 
M

mike

mike said:
I have the following line that I want to use a regexp to match:
I have tried the following pattern.
String pattern = "#define\\s[A-Z_]+\\s\\(\\"[A-Z_]+\\"\\)";
This is the input line that I want to match:
#define MY_NAME_INTERFACE ("GROUP_INTERFACE_04")
MY_NAME_INTERFACE - can contain any caps and underscore.
GROUP_INTERFACE_04 - can contain any caps and underscore as well as
digits at the end.

You forgot the digits in your pattern.

Use just "\"" to put a quote in a string, and do not try to protect it
from interpretation by the regexp engine at all. It is not special.

Thanks!

I missed about the " character.

//mike
 
L

Lothar Kimmeringer

Jussi said:
mike said:
String pattern = "#define\\s[A-Z_]+\\s\\(\\"[A-Z_]+\\"\\)"; [...]
#define MY_NAME_INTERFACE ("GROUP_INTERFACE_04")

You forgot the digits in your pattern.

Use just "\"" to put a quote in a string, and do not try to protect it
from interpretation by the regexp engine at all. It is not special.

in general there can be as much whitespaces as you like, so
\\s should better be \\s+


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 

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

Similar Threads

Help with code 0
<div> help 1
HELP PLEASE 4
regexp(ing) Backus-Naurish expressions ... 23
newbie Java regexp question 4
Help with regexp 5
I dont get this. Please help me!! 2
Need help with this script 4

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top