These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Regular expressions in batch

nettie65
Registered: Dec 15 2010
Posts: 7

I'm trying to create a regular expression to redact phone numbers. I'm currently using the following:
\(?(\d{3})\)?-?(\d{3})-(\d{4})|(\d{3})-(\d{4})|(\d{3}).(\d{4})
but the problem is we have parcel numbers formated as 999-9999-9999-99 and the expression is redacting the first half of the parcel number as well as numbers formated as credit card numbers.
 
Can anyone help me exclude numbers formated as 999-9999-9999-99.
 
Thanks bunches!!
 
Nettie

My Product Information:
Acrobat Pro 9.4.2, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You could add beginning (^) and end ($) of string anchors to prevent it from affecting longer runs of numbers.
nettie65
Registered: Dec 15 2010
Posts: 7
Thanks for responding. Where exactly does that go? like this?

^\(?(\d{3})\)?-?(\d{3})-(\d{4})|(\d{3})-(\d{4})|(\d{3}).(\d{4})$

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Yes, try that.
nettie65
Registered: Dec 15 2010
Posts: 7
Using ^\(?(\d{3})\)?-?(\d{3})-(\d{4})|(\d{3})-(\d{4})|(\d{3}).(\d{4})$ still redacts the first part of my parcel number.
parcel number = 179-0074-0025-00
The 179-0074- gets redacted. I have also tried ^\(\d{3})-(\d{4})$ and that produces no redaction of my phone number or the parcel number.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You might want to look at:

Validate Phone Numbers: A Detailed Guide by Jan Goyvaerts and Steven LevithanYou will need to add the "/" as appropriate to the provided code.

If you want to test for a 10 digit phone number and a 7 digit phone number, test for each one individually and do not try to bunch the code for both into one RegExp.

For the 7 or 10 digit phone number:

// 10 or 7 digit phone numbers
var RE_Phone = /^(?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})$/
if(RE_Phone.test(event.value) ) {
app.alert('Valid Phone Number\n' + RegExp.$1 + " " + RegExp.$2 + " " + RegExp.$3 , 3, 0);
} else {
app.alert('Invalid Phone Number', 1, 0);
}

It will accept "-", ".", " ", or no separator.

George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Try a regular expression like this:

var re = /^(\(?(\d{3})\)?-?(\d{3})-(\d{4})|(\d{3})-(\d{4})|(\d{3}).(\d{4}))$/;
nettie65
Registered: Dec 15 2010
Posts: 7
Thanks for responding gentlemen! I tried both examples to no avail.
I need to do this in a batch process so I can also set security, add watermark and redact phone numbers, social security numbers and credit card numbers. I'm using the "Mark Up Text Patterns" sequence.

I started out using the check boxes for phone number, social secuirty number and credit card but found that it also redacted the first part of the
parcel number(179-0074-0025-00).

I then started trying the regular expressions under the "Markup using a cutom text pattern (regular expression)" check box.
Unfortunatly, the examples given do not work at all under the "Mark Up Text Patterns". They simply don't redact anything, not even the phone number.

Any more guidance you could provide would be very much appreciated. Again, thanks for time in responding! :)
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
I see what you're doing now. I assumed you were using JavaScript somehow. Is that sequence provided by the AutoRedact plug-in? If so, you might see if it's documentation has any info.
nettie65
Registered: Dec 15 2010
Posts: 7
I did look at that and there was some documentatiion regarding character classes/set that looked promising but I've not gotten it to work yet. I'm trying to use [^-.0-9] at the end of the string.

Any other suggestions?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Maybe their customer service can help. I don't have any experience using that plug-in.
nettie65
Registered: Dec 15 2010
Posts: 7
I finally used (?:\(?(\d{3})\)?[-.]?)?(\d{3})[-.](\d{4})[^-.] and it is not redacting my parcel numbers. However, it is redacting any 9 digit zip code 12345-1234. Could you give any insight as to why?
Thanks guys!