RegEX

From: steve22 Feb 2010 16:25
To: ALL1 of 6
Hello :C I am building a 400ish page catalogue for work with ZMags. They let you use Regular Expressions to build links. This excites me but I am not sure how they work. I need it to look for something like T112R045N but basically any Txxxxxxxx. So T followed by 8 letters or numbers. What is that? I wish to learn RegXP too.

xxx
From: Peter (BOUGHTONP)22 Feb 2010 18:23
To: steve 2 of 6
Well "T followed by 8 letters or numbers" is this:
code:
T[A-Z0-9]{8}


However, if you need to be sure that is isolated (i.e. not found in "ATTENTIVENESS"), then you want to use word boundary markers also:
code:
\bT[A-Z0-9]{8}\b

The \b matches the zero-width boundary between a "word character" (alpha,number,underscore) and a "non-word character" (everything else), in either direction.
If you have different/stricter rules, potentially a different expression is needed.

Also, that'll still match "TENTATIVE" though - so you'll need to clarify if you want, for example, at least 1 numeric digit, and if the position of that number might be important.

Similarly, is case important - should "t112r045n" match?
(If so, you can probably plonk (?i) at the start to set case-insensitive mode.)
EDITED: 22 Feb 2010 18:26 by BOUGHTONP
From: steve22 Feb 2010 19:27
To: Peter (BOUGHTONP) 3 of 6
I had figured out the T[A-Z0-9]{8} eventually but did not know about the isolated bits. Case should be fine!

ZMags link tool is doing RegEx bad and making errors even with their example one, so they are fixing it over night :C THANK YOU PETER :C
From: CHYRON (DSMITHHFX)27 Feb 2010 14:15
To: Peter (BOUGHTONP) 4 of 6
I love RE's but they can sure fuck things up fast. I always do a compleat code bu before running a global search & replace on RE's.
From: Peter (BOUGHTONP)27 Feb 2010 14:29
To: CHYRON (DSMITHHFX) 5 of 6
I'm not sure what a "code bu" is, but yes - any global search and replace is something to be careful about, and an imprecise regex is especially liable to unintentionally change things.

Still a great and underused/misused tool though.
From: CHYRON (DSMITHHFX)27 Feb 2010 19:53
To: Peter (BOUGHTONP) 6 of 6
"bu" stands for beatific underling, of course...