• Post Reply Bookmark Topic Watch Topic
  • New Topic

regular expressions  RSS feed

 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are they part of the java API? If I need to enforce certain rules for certain patterns of strings can I use a rule engine to do that? how different is it to use regular expressions? Can I use regular expressions to change certain patterns during the build process and leave the code intact? Do I need any extra libraries?

Thanks,
Vasu
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vasu,
Are they part of the java API?

Yes, as of jdk 1.4
If I need to enforce certain rules for certain patterns of strings can I use a rule engine to do that?

Yes, but regex isn't commonly thought of as a rule engine.

how different is it to use regular expressions?

Very easy, in my opinion.

Can I use regular expressions to change certain patterns during the build process and leave the code intact?

Not sure what you're asking here?

Do I need any extra libraries?

not if you're using jdk 1.4

Thanks,

Happy to help,
M
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I use regular expressions to change certain patterns during the build process and leave the code intact?
Not sure what you're asking here?

I think the OP wants to change his RE without rebuilding his Java classes.
Such would certainly be possible, all you need to do is store the RE (which are just text strings) in a ResourceBundle or some other data store external to the application (a database-centric application might use a database table, an XML-based application an XML file, etc.).
You can then change the RE, reload the application, and the new RE will be used instead of the old one.
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an actual situation like this. I have some very large JSPs. The HTMLs generated dynamically are posing some problems at the clients' place where the web based application is exceeding the bandwidth that they have at their place. We wanted to cut out any extra spaces, comments etc from the HTMLs generated ( by stripping all extra spaces in the printouts of JSPs). But this should not be done in the JSPs in the code but only should happen during build process so that development code is legible and easily mantainable. This should happen everytime build happens. It should not affect development code.
Hope I made myself clear.
Thanks,
Vasu
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parsing "ignorable" whitespace from HTML-generating JSPs can easily be a mission impossible unless your JSPs are XML-compliant (.jspx).
I would rather look into compressing the output with a GZIP filter (for requests that declare GZIP as a supported encoding in the HTTP header "Accept-Encoding"):
Two Servlet Filters Every Web Application Should Have
GZIPFilter.java
Orion Filter Tutorial , Lesson 5, Compressing the Response
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try the following, but no promises.
M
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is cool but it strips only the HTML files. My HTMLs are dynamically generated. I need the stripping to be done in the JSPs so the resultant servlet's printlns should only print what is absolutely needed.
Plus, we are using JDk1.3.

Thanks,anyway. I got an idea now.

Vasu
[ April 14, 2004: Message edited by: vasu maj ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vasu,
It strips out whatever you feed it: It'll do JSPs as well, I think. But you're right, this is a jdk 1.4 thing, so you'll have to use ORO with jdk 1.3.
All best,
M
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Max, could you explain how this regexp behaves with meaningful space such as <img ... alt="Meaningful      Space">?
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same question
Vasu
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pattern

,"(?m)^\\s*(?://.*)?\\s*$

should be read as follows:
"This pattern will be applied to a String that has multiple lines" == (?m)
"look for the beginning of line character" == ^
"followed by zero or more blank spaces" == \\s*
"optionally followed by a Java comment" == (?://.*)?
"followed by zero or more blank spaces" == \\s*
"followed by an end-of-line character" == $
"if the Regex Engine finds something that meets this criteria, replace it with an empty String".
Thus, it should ignore the kinds of meaningful space you're describing, because they don't meet the criteria of being preceeded by a beginning of line character, and nothing but a beginning of line character, so help them God.
HTH,
M
[ April 14, 2004: Message edited by: Max Habibi ]
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Max.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!