Help Me Solve This Java Regex Problem - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Help 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> (.+) (</p> ", "" ;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: 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. |
Please Help Me Solve This MATLAB Problems • Regex Phone Number(nigerian Format) In Python • Help Me Solve This AJAX Problem. • 2 • 3 • 4
Linux Experts Get In • I Wanna Learn App Development • Windows 10 Original Files October 2018 Update Version 1809
(.+) (</p>
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.