RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(?:(?:(?<Feet>\d+)[ ]*\'){0,1}[ ]*(?<WholeInches>\d*(?![/\w])){0,1}(?:[ ,\-]){0,1}(?<Fraction>\d*\/\d*){0,1}(?<Decimal>\.\d*){0,1}\")|(?:(?<Feet>\d+)[ ]*\'[ ]*){1}
Description
I needed an expression to extract measurements from text to extract steel sizes from product descriptions, and I came up with this. It will only match on measurements that have complete dimensions (i.e. measurements with foot and inch marks in the positions you'd expect them). My personal experience required that I also be a little lax and allow measurements such as: .125 (for wall thicknesses and sheet metal thicknesses) with no inch marks. You can accomplish this by including: |(?&lt;Decimal&gt;\.\d{3}\&quot;*) to the end of the expression Hope it helps you.
Matches
1/4" x 2.125" Flat 44W x 20'3.5" | 1/8" x 4" C-1018 flat x 14' 5-1/4"
Non-Matches
44W | 8 @ 21 W.F. beam | 1/4 x 2.125 Flat 44W x 20
Author Rating: Not yet rated. Trevor Braun
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials