Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string matching help

Status
Not open for further replies.

tsp120

Programmer
May 21, 2003
52
US
Are there any good resources for detailed string matching equations?

What I need to do is go through files in a directory. The files that I need to pull out contain:

following a "/"
Any sequence of characters followed by an underscore followed by any sequence of characters, followed by an underscore, etc. It's not always the same size sequences of characters and not the same amount of sequences of characters.

After the final underscore there is a sequence of 4, 13, or 14 numbers in which I need to obtain the first 4.

Following these numbers I have the suffix of the file (.xxx)


so for instance, some possible file names could be:

/cit_stat_pol_2849.dat
/xo_tnn_58494957712553.suf
/map_addr_0039.suf

in the above examples I would like to pull out and set into variables:
1: "cit_stat_pol_", "2849", "dat"
2: "xo_tnn_", "5849", "suf"
3: "map_addr_", "0039", "suf"


If you can think of a formula for that could you please help me, or at least provide me with a resource with detailed instructions on how to do some of the things I will need to do?

Thanks!
 
Try this one:
Code:
my ($name, $value, $extention) = m/([a-z_]+)(\d\d\d\d)\d*\.([a-z]{3})/i ;

Be carefull, this should give you the right value, but only if you're using it on some text that match all the rules you said.
For example, it will crash with: aze_rt_12.tot

Hope it helps.
 
I actually ended up figuring it out on my own once I visited that link, but naq2 you showed me a much more efficient and neat way of writing it.

Thanks to both of you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top