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

RegExp pattern / replace function 0
Help with code 4
I need help with a Gemini prompt 1
Help with code 0
<div> help 1
HELP PLEASE 4
regexp(ing) Backus-Naurish expressions ... 23
newbie Java regexp question 4

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top