Regular Expression Help (Again)
Discussion
think Regex is the wrong thing to use personally. Most languages have some variant of split/explode to do this sort of thing.
Either way (regex or code), your main problem will be the fact that it's hyphen delimited, what happens when a company name has a hyphen in it?
Can you change the delimiting hyphen to something more uncommon in general usage? The pipe "|" symbol is a common delimiter.
Either way (regex or code), your main problem will be the fact that it's hyphen delimited, what happens when a company name has a hyphen in it?
Can you change the delimiting hyphen to something more uncommon in general usage? The pipe "|" symbol is a common delimiter.
If the first sequence is digits, then to get each section between hyphens, and allowing hyphens in the company name, then I would start with:
^(\d+)-(.*)-([^\-]+)-([^\-]+)-([^\-]+)-([^\-]+)$
That was fun to type on a phone!
If I was on my computer at home, I would've tried it out.
Although, as has been mentioned, a string split on "-" would be easier...
^(\d+)-(.*)-([^\-]+)-([^\-]+)-([^\-]+)-([^\-]+)$
That was fun to type on a phone!
If I was on my computer at home, I would've tried it out.
Although, as has been mentioned, a string split on "-" would be easier...
If the files are stored in a single folder somewhere, and you can access them - you could do something like this:
Filename: 123456-COMPANY-BRAND-ITEM-VERSION.txt
ls 123456* |awk -F "-" '{print $1 "\n" $2 "\n" $3 "\n" $4}'
123456
COMPANY
BRAND
ITEM
That separates the data held within the file name which I assume is what you are wanting?
Filename: 123456-COMPANY-BRAND-ITEM-VERSION.txt
ls 123456* |awk -F "-" '{print $1 "\n" $2 "\n" $3 "\n" $4}'
123456
COMPANY
BRAND
ITEM
That separates the data held within the file name which I assume is what you are wanting?
dibbers006 said:
Tribbles!
That looks awesome but it's not finding any matches?
LINKY
... I'm going to presume it's my fault...
I did say that I didn't have time to try it That looks awesome but it's not finding any matches?
LINKY
... I'm going to presume it's my fault...


Remove the last "-([^\-]+)" from it - I couldn't see your example when I was typing it in, and I accidentally matched too many things.
Each item is a group in its own right.
And if the company name has hyphens in it:
I did spend around 4 years basically writing regular expressions!
dibbers006 said:
I'm happy to be branded ignorant here, but where would one enter the highlighted line? Is that a Terminal command?
Yes, it's a terminal command.TonyRPH said:
If the files are stored in a single folder somewhere, and you can access them - you could do something like this:
ls 123456* |awk -F "-" '{print $1 "\n" $2 "\n" $3 "\n" $4}'
<snip>ls 123456* |awk -F "-" '{print $1 "\n" $2 "\n" $3 "\n" $4}'
How it works: 'ls' is the command to list files. The command "awk" breaks the line into columns, based on the delimiter of your choosing (in this case a '-')
The output of ls is 'piped' to awk using the '|' (pipe or more character)
'print' just 'tells' awk to print each column separated by the '-', $1 is the first column, $2 the second and so on.
The "\n" is a line feed to put each matched column on a new line.
So if you omit $1 it looks like this:
ls 123456* |awk -F "-" '{print $2 "\n" $3 "\n" $4}'
COMPANY
BRAND
ITEM
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


