0

In ruby I have this

ip_address.sub(/\/\d+/,'')

Is there any equivalent in java?

1
  • 2
    If ip_address is a String then I'm pretty sure there is an equivalent. I'm no ruby expert so I'd have to guess: what is that meant to do? And what did you try so far? Commented Dec 12, 2018 at 15:58

2 Answers 2

2

ip_address.replaceFirst("regex", "replacement");

This is the Java equivalent of Ruby's sub(). If you want something like gsub(), this other function can be used:

ip_address.replaceAll("regex", "replacement");

Sign up to request clarification or add additional context in comments.

Comments

1

You can try the following regular expression:

/\d+

i.e.:

ipAddress.replaceAll("/\\d+", "")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.