CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Regular Expression Question...PLEASE?

 



Uncle_Jake
Novice

Dec 18, 2013, 9:32 AM

Post #1 of 7 (964 views)
Regular Expression Question...PLEASE? Can't Post

In PERL, I'm trying to use a regular expression that will replace two digits at the beginning of a string with 'testtext'. There will be instances of strings that have 0, 1, 2, and more digits at the beginning, but I only want to substitute 'testtext' for those strings that have EXACTLY two digits at the beginning. For instance:

1Sallywentthisway --> gets skipped in the replace for having only 1 digit
00tomwentthatway --> 00 is replaced with testtext
123joestayedstill --> gets skipped in the replace for having over 2 digits
11Billisgone --> 11 is replaced with testtext

This line of PERL code is not enough:

$segment =~ s/^\d{2}/testtext/;

That code will change the 123joestayedstill to testtext3joestayedstill

Where is my regular expression out of joint?

THANK YOU!


Kenosis
User

Dec 18, 2013, 10:30 AM

Post #2 of 7 (958 views)
Re: [Uncle_Jake] Regular Expression Question...PLEASE? [In reply to] Can't Post

Cross-posted at PerlMonks.


Uncle_Jake
Novice

Dec 18, 2013, 12:43 PM

Post #3 of 7 (952 views)
Re: [Kenosis] Regular Expression Question...PLEASE? [In reply to] Can't Post

Fabulous! Worked exactly like I needed...and also taught me how to do something else as well. THANK YOU.


Laurent_R
Enthusiast / Moderator

Dec 18, 2013, 3:22 PM

Post #4 of 7 (941 views)
Re: [Uncle_Jake] Regular Expression Question...PLEASE? [In reply to] Can't Post

OK, you may try gratuitious sarcasm as you wish, but you should know that it is considered good practice to inform people about cross posting on this type of forum. You are asking people to help you, it is nice to tell people that are trying to help you for free that you have asked the question elsewhere and that the right answer might have already provided. This might avoid duplicate work from people who are trying to help you for free. In the case in point, you have received the relevant (and I think correct) answer on Perl Monks, why should people here spend time trying to give you an answer that you already have?

Kenosis is spending a lot of effort trying to help other people such as you on this forum and on others, please don't discourage him. Please avoid this kind of sarcasm next time, it is not nice toward people who are trying to help you for free.


Uncle_Jake
Novice

Dec 18, 2013, 7:28 PM

Post #5 of 7 (928 views)
Re: [Laurent_R] Regular Expression Question...PLEASE? [In reply to] Can't Post

I was being honest...and serious. I was helped a great deal and sincerely appreciative. I was even inspired to do something else and found the answer to be similar to the one I was given. I didn't know the answer was found on another site before this one.


(This post was edited by Uncle_Jake on Dec 18, 2013, 7:30 PM)


Kenosis
User

Dec 18, 2013, 7:38 PM

Post #6 of 7 (925 views)
Re: [Laurent_R] Regular Expression Question...PLEASE? [In reply to] Can't Post

Thank you, Laurent_R, for your kind words.


Kenosis
User

Dec 18, 2013, 7:49 PM

Post #7 of 7 (924 views)
Re: [Uncle_Jake] Regular Expression Question...PLEASE? [In reply to] Can't Post

Am glad that you found help, and certainly didn't mean to be dismissive about your question by mentioning it had been cross-posted.

As you visit this and other these programming sites, you'll likely encounter others mentioning that a question has been cross-posted. PerlMonks has a node discussing what to say in such cases.

This being said, I do hope that you return with any Perl questions that you may have. I've found the expertise here quite impressive.


(This post was edited by Kenosis on Dec 18, 2013, 8:06 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives