Regular Expression Creator

  • Thread starter Arvind Varma Kalidindi
  • Start date
A

Arvind Varma Kalidindi

Hello,
I know that there is this java.util.regex package which can be
used for doing patten matching on text. But is there a java
program/application which will generate a regular expression for a
given string? In other words, if I give "Gabriel" as the input, it
should say that the regular expression will be ^[A-Z]+[a-zA-Z]*$ .
(Notice the "G" in Gabriel).
Can somebody give me some pointers towards building such an
application (if one doesn't exist)?

Regards,
Arvind.
 
M

Murray

Arvind Varma Kalidindi said:
Hello,
I know that there is this java.util.regex package which can be
used for doing patten matching on text. But is there a java
program/application which will generate a regular expression for a
given string? In other words, if I give "Gabriel" as the input, it
should say that the regular expression will be ^[A-Z]+[a-zA-Z]*$ .
(Notice the "G" in Gabriel).
Can somebody give me some pointers towards building such an
application (if one doesn't exist)?

Regards,
Arvind.

Wouldn't the number of valid regular expressions be potentially huge for any
given string?
 
F

Frank Buss

I know that there is this java.util.regex package which can be
used for doing patten matching on text. But is there a java
program/application which will generate a regular expression for a
given string?

System.out.println(".*")
 
M

Michael Borgwardt

Murray said:
I know that there is this java.util.regex package which can be
used for doing patten matching on text. But is there a java
program/application which will generate a regular expression for a
given string?
[]
Wouldn't the number of valid regular expressions be potentially huge for any
given string?

Infinite, actually. And that also holds for any given *set* of Strings.
 
B

bugbear

Arvind said:
Hello,
I know that there is this java.util.regex package which can be
used for doing patten matching on text. But is there a java
program/application which will generate a regular expression for a
given string? In other words, if I give "Gabriel" as the input, it
should say that the regular expression will be ^[A-Z]+[a-zA-Z]*$ .
(Notice the "G" in Gabriel).
Can somebody give me some pointers towards building such an
application (if one doesn't exist)?

String generateRegex(String target) {
return "^" + target + "$";
}

This solution doesn't escape any regex special
characters in target, which is left as an excercise.

HTH.

BugBear
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top