ColdFusion Regex Match for Digits of Exact Length -


i need assistance constructing regular expression in coldfusion application. apologize if has been asked. have searched, may not asking correct thing.

i using following search email subject line issue number:

rematchnocase("[0-9]{5}", mailcheck.subject) 

the issue number contains numeric values, , should 5 digits. working except in cases have longer number appears in string, such 34512345. takes first 5 digits of string valid issue number well.

what want retrieve 5 digit numbers, nothing shorter or longer. placing these list looped on , processed. perhaps need include spaces before , after in regex desired result?

thank you.

the general way exclude content occurring before/after match use negative lookbehind before match , negative lookahead afterwards. numeric digits be:

(?<!\d)\d{5}(?!\d) 

(where \d shorthand [0-9])

cf's regex supports lookaheads, unfortunately not lookbehinds, wouldn't work directly in rematch - doesn't matter in case because it's don't want, example, abc12345 match either - more want is:

\b\d{5}\b 

where \b "word boundary" - roughly, checks change between "word character" , non-word character (or visa versa) - in case first \b check there not 1 of [a-za-z0-9_] before first digit, , second \b check there isn't 1 after fifth digit. \b not append characters match (i.e. zero-width assertion).

since you're not dealing case, don't need nocase variable , can write:

rematch( '\b\d{5}\b' , mailcheck.subject ) 

the benefit of on checking spaces result 5 digits (no need trim), downside match values such [12345] or 3.14159^2 not want?

to check spaces, or start/end of string, can do:

rematch( '(?:^| )\d{5}(?= |$)' , mailcheck.subject ) 

then use trim on each result remove spaces.

if that's not you're after, go ahead , provide more details.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -