The moose likes Beginning Java and the fly likes Regex to use in replaceall Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Regex to use in replaceall" Watch "Regex to use in replaceall" New topic
Author

Regex to use in replaceall

Ram ank
Greenhorn

Joined: Apr 28, 2011
Posts: 10
Hi Guys

I want to add newline after occurence of IPV4 address in my string. I am trying with output.replaceAll("?<=(\\d{1,3}\\.){3}\\d{1,3}", "\n");
But it is throwing Exception. Please help me.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3143
Ram ank wrote:But it is throwing Exception. Please help me.


You need to TellTheDetails(⇐click)

Copy/paste the exact, complete error message, as well as the line of code that caused it.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3143
One thing jumps out at me though. As far as I know, you have to do

not just

Ram ank
Greenhorn

Joined: Apr 28, 2011
Posts: 10
It worked like this
with ?<ip> it stores the matching string and using it in replacement with ${ip}

output.replaceAll("(?<ip>(\\d{1,3}\\.){3}\\d{1,3})", "${ip}\n");

Thank you guys
 
 
subject: Regex to use in replaceall
 
Threads others viewed
IP address regular expression
using wildcards in java
distributed application
IP address validation using javascript
mock exam jstl core iteration custom tags
IntelliJ Java IDE