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: Regular Expressions:
Help w/ matching at the end of a string.

 



ericsemail
Novice

Mar 29, 2007, 9:55 AM

Post #1 of 4 (3498 views)
Help w/ matching at the end of a string. Can't Post

Hi--

I've searched through this thread but my problem is kind of specific and I haven't found an example that reflects what I'm trying to do.. I have a string: "XXXXXX-x50xx" i'm trying to match the end, in this case the "xx" at the end but in general I'm trying to match the last non-numeric characters until the number. Sometimes the string may be "XXXX-x50xxXX" so in this case I'd want to match "xxXX". In other cases it may look like "XXXXXX_5X". Anyway, when I do the match, I believe it's finding it, except, it's not storing the match in $1 or $& and I can't figure out why. Maybe my regular expression is wrong? I've very new to this. Can someone please help me out? Thanks


ericsemail
Novice

Mar 29, 2007, 10:13 AM

Post #2 of 4 (3497 views)
Re: [ericsemail] Help w/ matching at the end of a string. [In reply to] Can't Post

Blah--figured it out:

/(\D*)$/;

I was putting the '$' in the front like: /$(\D*)/; and it was matching, but...wasn't working... with the $ at the end, everything is great. :)


ericsemail
Novice

Mar 29, 2007, 10:20 AM

Post #3 of 4 (3496 views)
Re: [ericsemail] Help w/ matching at the end of a string. [In reply to] Can't Post

Ok--ran into my next problem if anyone is alive out there--now I'm trying to get the '50' out. But--I can't search from the "end" because it's no longer located at the end. What to do?


KevinR
Veteran


Mar 29, 2007, 12:10 PM

Post #4 of 4 (3491 views)
Re: [ericsemail] Help w/ matching at the end of a string. [In reply to] Can't Post

/(\d+)/

or:

/.*?(\d+).*/
-------------------------------------------------

 
 


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

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