[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Regular expressions - retain one substring, replace another

Posted on 2006-11-17
5
Medium Priority
?
208 Views
Last Modified: 2006-11-18
In order to change the minimum font size in HTML to be 3, for a string such as:

   Font face="Times New Roman" size=1

it would be helpful to be able use two substrings:

   Font face=\"[A-Za-z0-9-]*\" size=
   [12]

and then retain the the first substring in the replace, while modifying the second substring.

in some versions of vi, this could be done with something like:

  s/\(Font face=\"[A-Za-z0-9-]*\" size=\)\([12]\)/\13

Please indicate whether something similar can be done in java.

Thanks.

0
Comment
Question by:joex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17964594
Try

String s = "Font face=\"Times New Roman\" size=1";
s = s.replaceAll("(Font face=\"Times New Roman\" size=)(\\d+)", $1+"3");
0
 

Author Comment

by:joex
ID: 17965098
The above won't compile - the $1 is not recognized
Also, perhaps it replaces all sizes with 3 rather than just sizes 1/2.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 17965127
>>The above won't compile - the $1 is not recognized

Sorry -that should be

, "$1+3");


>>Also, perhaps it replaces all sizes with 3 rather than just sizes 1/2.


s = s.replaceAll("(Font face=\"Times New Roman\" size=)([1-2])", "$1+3");
0
 

Author Comment

by:joex
ID: 17965162
The following appears to work:

   s.replaceAll("(Font face=\"Times New Roman\" size=)([1-2])", "$13");

The "+" appears otherwise.

Thanks a lot!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17965187
Good - nice to see a fellow vi user ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question