Add Different Prefix Based On Value Of 8 Digit Number

A swapping-ground for Regular Expression syntax

Add Different Prefix Based On Value Of 8 Digit Number

Postby Shawnny Canuck » Tue Nov 01, 2016 10:27 pm

Hello,

I need to add a prefix to an 8 digit number located within a string. This 8 digit number is sequential so it changes. On top of that the prefix can be one of two variations depending on its value. So if the 8 digit number is lower than 14999999 I need it to add the LO prefix if it is higher than 15000000 I need to add the HI prefix. Here is an example:

LO Prefix Example

Before Regular Expression
14999999 - Title 1 - Title 2
After Regular Expression
LO14999999 - Title 1 - Title 2

HI Prefix Example

Before Regular Expression
15000000 - Title 1 - Title 2
After Regular Expression
HI15000000 - Title 1 - Title 2

Is this even possible using regular expressions? Any help you could provide would be greatly appreciated.
Shawnny Canuck
 
Posts: 18
Joined: Wed Jul 30, 2014 7:15 pm

Re: Add Different Prefix Based On Value Of 8 Digit Number

Postby therube » Wed Nov 02, 2016 12:54 am

I'm sure JavaScript Renaming could do that.

Or just select the first 15 million "LO"'s & prefix the LO to them.
The come back & select the second 15 million "HI"'s & prefix the HI to that group.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Add Different Prefix Based On Value Of 8 Digit Number

Postby Admin » Wed Nov 02, 2016 1:36 am

Yes, Javascript Renaming can do that (Special 14) in one pass. If you have a commercial license I can post the script. thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Add Different Prefix Based On Value Of 8 Digit Number

Postby Shawnny Canuck » Wed Nov 02, 2016 5:27 am

Thanks for the quick reply guys. Unfortunately, I do not have a commercial license so I guess I will have to try and figure this out on my own. Thanks for pointing me in the right direction though.
Shawnny Canuck
 
Posts: 18
Joined: Wed Jul 30, 2014 7:15 pm

Re: Add Different Prefix Based On Value Of 8 Digit Number

Postby cbanzet » Tue Jun 20, 2017 7:33 pm

It could be done in 4 passes:

Match: (0)(\d{7})(.*)
Replace: LO\1\2\3

Match: (1)([0-4])(\d{6})(.*)
Replace: LO\1\2\3\4

Match: (1)([5-9])(\d{6})(.*)
Replace: HI\1\2\3\4

Match: ([2-9])(\d{7})(.*)
Replace: HI\1\2\3

This is from a complete noob. Surely someone can do better.
cbanzet
 
Posts: 3
Joined: Tue Jun 20, 2017 6:53 pm


Return to Regular Expressions


cron