Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help in creating reg expression

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have one String like this

<Ele name="gunjan<" unit="string" >
<Value>there #@!%$^&<*()(</Value>
</Ele>


I need one regular expression where i want to search for any word which starts with =" and ends with ". I have to take the word in between and do some replacement.

What would be the expression for this.
I tried this way but not working.


Ex:

="gunjan<"


output :

="gunjan<lt&"



i have done the replacement part,but not ablt to form the expression for search

Any help would be highly appreciated
 
Marshal
Posts: 79531
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go to the Regular Expressions part of the Java Tutorials. Look for the bits about word boundaries with \b.
 
Gunjan Kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have tried like this but replacing the string back to original string is very tedious.

how do you use boundary to achieve this

Input:<A name="123<45" />
desired output:<A name="123<lt&45"/>

 
Campbell Ritchie
Marshal
Posts: 79531
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try a StringBuilder searching for indexOf("=<"). Might be easier than a regular expression.
 
Gunjan Kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This code works fine with one input but doesn't work for more than one input.
Scenario 1:Working
input:<Value>test for < syntax</value>
output:<Value>test for <lt; sysntax</value>

Scenario 2:not Working
input:<Value>test for < syntax</value><Value>test for < syntax</value>
output:<Value>test for <lt; syntax</value><Value>test for <lt; syntax</value>


but this is giving wrong result.
Any suggestion
 
Gunjan Kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what would be the regular expression for requirement like this.

Input string : <Value>abc<h</value>
Output: <Value>abc<lt;h</value>

i want to change all occurance of < but first and last.
I tried but not able to change only < other than first and last
 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not <lt; but should be <

Why not output it correctly to the XML file?
 
It was the best of times. It was the worst of times. It was a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic