Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
In ruby I have this
ip_address.sub(/\/\d+/,'')
Is there any equivalent in java?
ip_address
String
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:
sub()
gsub()
ip_address.replaceAll("regex", "replacement");
Add a comment
You can try the following regular expression:
/\d+
i.e.:
ipAddress.replaceAll("/\\d+", "")
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
ip_addressis aStringthen 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?