₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,324,993 members, 8,419,847 topics. Date: Thursday, 04 June 2026 at 02:31 AM

Toggle theme

Help Me Solve This Java Regex Problem - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingHelp Me Solve This Java Regex Problem (1186 Views)

1 Reply

Help Me Solve This Java Regex Problem by DavidTheGeek(op): 8:39pm On Apr 14, 2017
So i have a string...

example:

String string = "<p>This is a string</p> yes it is but <p>you already know</p> hahaha";

I want to replace the first <p> </p> in this case <p>This is a string</p>.

Note: I don't know the exact word(s) that could be inside the <p> </p>

So here's the regex i wrote..

String newstring = string.replaceFirst("(<p>wink (.+) (</p>wink", ""wink;

It's not working.

It replaces <p>This is a string</p> yes it is but <p>you already know</p> instead of only <p>This is a string</p>.

Anyone, please solve this for me.

** Please click quote to view my regex well.. Silly smiley **
Re: Help Me Solve This Java Regex Problem by asalimpo(m): 1:06am On Apr 15, 2017
I see you took your name inspiration from one DanielTheGeek here.
Try rolling up your sleeves and writing your own solution instead of depending on regex. String manipulation practice is one of the best ways to cut your teeth in programming.
Re: Help Me Solve This Java Regex Problem by DavidTheGeek(op): 2:13am On Apr 15, 2017
asalimpo:
I see you took your name inspiration from one DanielTheGeek here.
Try rolling up your sleeves and writing your own solution instead of depending on regex. String manipulation practice is one of the best ways to cut your teeth in programming.
grin No i didn't, it's just a coincidence. Funny thing is, before the time i registered the profile, i wasn't really into the Programming section, i was more on the Webmaster section, so i didn't know there was someone called DanielTheGeek. Twas later i came across his profile and i even thought he was the one who mirrored my name, not until i saw his profile was registered before mine.

On the regex issue, i've found a way to manipulate the string to serve my purpose. Though i still hope to see someone else's solution.
1 Reply

Please Help Me Solve This MATLAB ProblemsRegex Phone Number(nigerian Format) In PythonHelp Me Solve This AJAX Problem.234

Linux Experts Get InI Wanna Learn App DevelopmentWindows 10 Original Files October 2018 Update Version 1809