Query regarding RegEx

E

emo

I am not good in regular expressions. I am struck with one issue,
please help.

I need to match the following texts

NOT 'any text' = 'any text'

the alternate text for 'any text' can be "any text" or any integer or
float value.

Patterns that should NOT match.

NOT ('value' = 'value')

the difference between the above two are parenthesis.

Thanks in advance,
-EM-
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

emo schreef:
| I am not good in regular expressions. I am struck with one issue,
| please help.
|
| I need to match the following texts
|
| NOT 'any text' = 'any text'
|
| the alternate text for 'any text' can be "any text" or any integer or
| float value.
|
| Patterns that should NOT match.
|
| NOT ('value' = 'value')
|
| the difference between the above two are parenthesis.

Try this one, but without more clarification, it is bound to fail on
some input:

"NOT ['\"](.[^'\"])['\"] = ['\"](.[^'\"])['\"]"

escaped for Java. Use Matcher.find() and Matcher.group(1),
Matcher.group(2) to find both values.

An integer or float value in a string is still just characters, so no
need to treat them special. You’ll have to find out what they are to
use them, though.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD4DBQFIFZnve+7xMGD3itQRAvakAJ0abbQFis90VKWj9vPyAdzUgjvD7ACYpOYn
u+7AtVfZ/MaHmNyfQ99uPQ==
=yuVc
-----END PGP SIGNATURE-----
 
R

Roedy Green

NOT 'any text' = 'any text'

the alternate text for 'any text' can be "any text" or any integer or
float value.

Patterns that should NOT match.

NOT ('value' = 'value')

More concrete examples would help. I suspect though that you will not
able to do this with pure regex. It cannot detect a repeated string.
You would have to detect that outside the regex. When you get into
that sort of complexity, normally you go up a notch to a parser.

See http://mindprod.com/jgloss/parser.html
 
D

Daniel Pitts

Roedy said:
More concrete examples would help. I suspect though that you will not
able to do this with pure regex. It cannot detect a repeated string.
You would have to detect that outside the regex. When you get into
that sort of complexity, normally you go up a notch to a parser.

See http://mindprod.com/jgloss/parser.html

You *can* do that in regex:

public class Matches {
public static void main(String[] args) {
String pattern = "NOT ([^(].*) = \\1";
String yes = "NOT 'any text' = 'any text'";
String no = "NOT ('value' = 'value')";
System.out.println("\"" + yes + "\".matches(pattern) = "
+ yes.matches(pattern));
System.out.println("\"" + no + "\".matches(pattern) = "
+ no.matches(pattern));

}
}
 
R

Roedy Green

You *can* do that in regex:

I am not at all clear what "this" is from his examples.

I have learned something new. I thought \1 was only for replacing.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top